安卓开发设置全屏

设置全屏的时候我们会在manifest中设置android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen"
然后程序可能会崩溃,原因很简单,继承自Activity就好了,继承AppCompatActivity自己就要写主题了


我们可以在res/styles.xml中设置一个新的全屏主题

<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="NoActivityFullscreen" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="windowNoTitle">true</item>
        <item name="windowActionBar">false</item>
        <item name="android:windowFullscreen">true</item>
        <item name="android:windowContentOverlay">@null</item>
    </style>

</resources>

然后在清单文件中写明活动的主题

 <activity android:name=".ui.SplashActivity"
            android:theme="@style/NoActivityFullscreen">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

猜你喜欢

转载自blog.csdn.net/qq_32252957/article/details/80147500