2016-04-22 106 views
0

当我点击一个按钮,我必须设置我的活动全屏。 在互联网上搜索我发现这样做的代码。全屏android

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> 

有人可以帮助我plase? 感谢

回答

0

有可能是在做一个更好的方式,但我用的是最简单的方法,

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

我把这个Activity类。

+0

我已经尝试过此操作,并且工作正常,但它不隐藏导航栏 –

+0

尝试编辑的代码。这也删除了标题栏。 – Fuzzie