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

问题描述:

你好,我有一个问题,我创建应用程序,将重复风景视频作为背景,但我不知道如何设置它在全屏。我正在Android Studio创建应用程序。应用程序将有这样的景观>enter image description here如何设置应用程序全屏运行

试试这个。

方式1 .SET在java代码清单

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

方式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"/> 

注意

  • 变化Activityandroid:theme
  • 设置getWindow().setFlags(WindowManager.LayoutParams.FILL_PARENT, WindowManager.LayoutParams.FILL_PARENT);
+0

开始使用您的近距离投票权 –

+1

如何使用它?Hello @NileshRathod。我一直在关注你很久。 – KeLiuyue

+0

我很高兴与你交流。我不生气。你很不错 。对不起,我可怜的英语。@ NileshRathod – KeLiuyue

在这里,你去..

要播放视频,创建一个文件夹名 “生” 下的 “资源” 文件夹中。将视频复制到“原始”文件夹下。请将视频名称保留为小字符。一旦这样做,请在下面做修改

  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> 
    

注 - 无需做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。

    这是你想要的吗?

开始=>