全屏安卓

时间:2016-04-22 13:47:10

标签: android android-fullscreen

当我点击一个按钮时,我必须将我的活动设置为全屏。 在互联网上搜索我找到了这样做的代码。

container.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                                | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                                | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
                                | View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
                                | View.SYSTEM_UI_FLAG_IMMERSIVE);

但是我做错了什么,因为状态栏和导航栏消失了,我的活动仍然保持相同的高度。

before

after

这是video.xml

<?xml version="1.0" encoding="utf-8"?>                               
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"              
    xmlns:tools="http://schemas.android.com/tools"                   
    android:layout_width="match_parent"                              
    android:layout_height="match_parent"                             
    android:fitsSystemWindows="true"                                 
    tools:context=".VideoActivity">                                  

    <include layout="@layout/content_video" />                       

    <android.support.design.widget.FloatingActionButton              
        android:id="@+id/close"                                      
        android:layout_width="wrap_content"                          
        android:layout_height="wrap_content"                         
        android:layout_gravity="bottom|center_horizontal"            
        android:layout_marginBottom="70dp"                           
        android:layout_marginRight="80dp"                            
        android:src="@drawable/phone"                                
        app:elevation="0dp"                                          
        app:backgroundTint="#44FF0000" />                            

    <android.support.design.widget.FloatingActionButton              
        android:id="@+id/screen"                                     
        android:layout_width="wrap_content"                          
        android:layout_height="wrap_content"                         
        android:layout_gravity="bottom|center_horizontal"            
        android:layout_marginBottom="70dp"                           
        android:layout_marginLeft="80dp"                             
        android:src="@drawable/fullscreen"                           
        app:elevation="0dp"                                          
        app:backgroundTint="#44000000"/>                             

</android.support.design.widget.CoordinatorLayout>  

这个content_video.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context=".VideoActivity"
    tools:showIn="@layout/video"
    android:id="@+id/layout"
    android:orientation="horizontal">

    <RelativeLayout
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#000000">
    </RelativeLayout>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:text="@string/string_video_id"
        android:id="@+id/conference_id"
        android:textColor="@android:color/white"
        android:enabled="false"
        android:focusable="false"
        android:alpha="0.5"
        android:background="@color/button_background"
        android:paddingLeft="10dip"
        android:paddingTop="5dip"
        android:paddingRight="10dip"
        android:paddingBottom="5dip"
        android:layout_marginBottom="20dp"
        android:layout_marginLeft="10dp"
        android:gravity="bottom"
        android:layout_alignParentBottom="true"/>

</RelativeLayout>

有人可以帮助我吗? 感谢

3 个答案:

答案 0 :(得分:0)

可能有更好的方法,但我使用的最简单的方法是,

    // Fullscreen
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

我把它放在Activity类中。

答案 1 :(得分:0)

 @Override
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);
    if (hasFocus) {
        getWindow().getDecorView().setSystemUiVisibility(5894);

    }
}

我希望它能完成工作

答案 2 :(得分:0)

 getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

检查t his source