如何设置应用程序以全屏运行

时间:2017-10-10 13:57:18

标签: java android

您好我有一个问题我创建的应用程序将重复横向视频作为背景但我不知道如何全屏设置它。我在Android工作室创建应用程序。应用会有这样的格局> enter image description here

2 个答案:

答案 0 :(得分:1)

试试这个。

清单

中的

方式1 .set

<activity
    ...
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen" />
java代码中的

方式2 .set

@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);

}
清单中的

方式3 .set并在样式中设置

<?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>
清单中的

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

注意

  • 更改android:theme。{/ li>的Activity
  • 设置getWindow().setFlags(WindowManager.LayoutParams.FILL_PARENT, WindowManager.LayoutParams.FILL_PARENT);

答案 1 :(得分:0)

你去..

要播放视频,请创建一个文件夹名称&#34; raw&#34;在&#34; res&#34;夹。将您的视频复制到&#34; raw&#34;夹。请将视频名称保留为小字符。完成后请进行以下修改

  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>
    

  2. 注意 - 无需在AndroidManifest文件中进行任何更改。

    1. MainActivity.java

      公共类MainActivity扩展了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>
      
    3. `

      注意 - 有一点需要注意的是,videoview应该是父布局的直接子节点,其他视图/布局将在videoview之后出现。

      这是你想要的吗?