AppCompatActivity透明化处理

本文解决了

有关AppCompatActivity透明化处理的失败探索历程

当Activity继承于AppCompatActivity时,只能使用Theme.AppCompat下的主题。而这些主题并没有Translucent.提示错误: 
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.

可以采用自定义主题来弥补AppCompat中无透明主题,方式如下:

<!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/theme</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:background">@color/translate</item>
    </style>
    <!--全屏加透明-->
    <style name="TranslucentFullScreenTheme" parent="FullScreenTheme">
        <item name="android:windowBackground">@color/translate</item>
        <item name="android:windowIsTranslucent">true</item>
    </style>
    <!--全屏-->
    <style name="FullScreenTheme" parent="AppTheme">
        <item name="android:windowFullscreen">true</item>
        <item name="android:windowNoTitle">true</item>
    </style>
    <!--透明,有任务栏电量时间等-->
    <style name="NoTitleTranslucentTheme" parent="AppTheme">
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowBackground">@color/translate</item>
        <item name="android:windowIsTranslucent">true</item>
    </style>

猜你喜欢

转载自blog.csdn.net/tgvincent/article/details/80881081