Android教程-全屏姿势-Activity和AppCompa

2018-11-22  本文已影响0人  虎三呀

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>
上一篇下一篇

猜你喜欢

热点阅读