Android全屏--兩種activity的實現方式

Java代碼設置

requestWindowFeature(Window.FEATURE_NO_TITLE);//這行代碼一定要在setContentView之前,不然會閃退
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

主題設置

自帶可設置全屏的主題有:

@android:style/Theme.NoTitleBar.Fullscreen
@android:style/Theme.Black.NoTitleBar.Fullscreen
@android:style/Theme.Holo.NoActionBar.Fullscreen
@android:style/Theme.Light.NoTitleBar.Fullscreen
@android:style/Theme.Material.NoActionBar.Fullscreen
@android:style/Theme.Translucent.NoTitleBar.Fullscreen
@android:style/Theme.Wallpaper.NoTitleBar.Fullscreen
@android:style/Theme.DeviceDefault.NoActionBar.Fullscreen
@android:style/Theme.Holo.Light.NoActionBar.Fullscreen
@android:style/Theme.Material.Light.NoActionBar.Fullscreen
@android:style/Theme.DeviceDefault.Light.NoActionBar.Fullscreen

AppCompatActivity全屏姿勢

Java代碼設置

getSupportActionBar().hide();
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

主題設置

<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- 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.NoTitleBar.Fullscreen" parent="AppTheme">
        <item name="android:windowFullscreen">true</item>
        <item name="windowNoTitle">true</item>
        <item name="windowActionBar">false</item>
    </style>
</resources>

小知識點:

<item name="windowNoTitle">true</item> 
可以實現去title,但是android還有一種 
<item name="android:windowNoTitle">true</item>,
使用後者替代前者不可以起到去title的作用

<item name="windowActionBar">false</item>
也有這樣的形式: <item name="android:windowActionBar">false</item>

但是
<item name="android:windowFullscreen">true</item>
沒有 <item name="windowFullscreen">true</item>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章