-1

Hello i have one problem i'm creating app that will repeat landscape video as background but i don't know how to set it in full screen. I'm creating app in Android studio. App will have landscape like this>enter image description here

Foxtrot
  • 35
  • 3

2 Answers2

1

Try this .

way 1.set in the manifest

<activity
    ...
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen" />

way 2.set in the java code

@Override

public void onCreate(Bundle savedInstanceState) {

   super.onCreate(savedInstanceState);

   // add this before setContentView methood ,and after super
   requestWindowFeature(Window.FEATURE_NO_TITLE); 

   getWindow().setFlags(WindowManager.LayoutParams.FILL_PARENT, WindowManager.LayoutParams.FILL_PARENT);  

   setContentView(R.layout.activity_main);

}

way 3.set in the manifest and set in the style

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <style name="theme_fullScreen" parent="android:Theme.Black"> 
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowFullscreen">true</item>
    </style> 
</resources>

in the manifest

<activity android:name=".LoginActivity"
    android:theme="@style/theme_fullScreen"/>

Note

  • change the android:theme of the Activity.
  • set getWindow().setFlags(WindowManager.LayoutParams.FILL_PARENT, WindowManager.LayoutParams.FILL_PARENT);
KeLiuyue
  • 8,149
  • 4
  • 25
  • 42
0

Here you go..

To play the video, create one folder name "raw" under "res" folder. Copy your video under "raw" folder. Please keep video name in small characters. Once done please do below modifications

  1. style.xml

    <!-- Base application theme. -->
    
    
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>
    
    <style name="AppTheme.FullScreen" parent="AppTheme">
        <item name="android:windowFullscreen">true</item>
    </style>
    

Note - No need to do any changes in AndroidManifest file.

  1. MainActivity.java

    public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_main);
    
        VideoView view = (VideoView) findViewById(R.id.videoView);
        Uri uri = Uri.parse("android.resource://"+getPackageName()+"/"+R.raw.samplevideo);
        view.setVideoURI(uri);
        view.start();
    
        // To keep video in loop
        view.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            @Override
            public void onPrepared(MediaPlayer mp) {
                mp.setLooping(true);
            }
        });
    }
    

    }

  2. activity_main.xml

    `

        <VideoView
            android:id="@+id/videoView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            tools:layout_editor_absoluteX="0dp"
            tools:layout_editor_absoluteY="0dp" />
    
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Hello World!"
            android:textSize="30dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent"></TextView>
    
    </android.support.constraint.ConstraintLayout>
    

`

Note - One thing keep in mind that videoview should be immediate child of parent layout, others views/layout will come after videoview.

Is this what you want?

Flutterian
  • 1,761
  • 1
  • 21
  • 47