Android設(shè)置Activity透明背景樣式(記錄)

來源 Geroff博客

https://blog.csdn.net/fengyulinde/article/details/81080569
內(nèi)容如下:
??給Activity指定主題樣式時,如果activity繼承AppCompatActivity,則必須指定theme為Theme.AppCompat或者其子類,否則會報錯。
第一,不設(shè)置布局文件背景顏色或者設(shè)置背景顏色為透明;
第二,在styles.xml文件中添加如下樣式,可根據(jù)情況設(shè)置所需屬性,但是,android:windowBackgroundandroid:windowIsTranslucent這兩個一定要設(shè)置,代碼如下:

 <!--繼承Theme.AppCompat.NoActionBar,不顯示標題欄-->
    <style name="TransparentTheme" parent="Theme.AppCompat.NoActionBar">
        <!--不設(shè)置activity進入和退出動畫樣式-->
        <item name="android:windowAnimationStyle">@null</item>
        <!--設(shè)置窗口的背景為透明,設(shè)置透明背景必須要設(shè)置此項-->
        <item name="android:windowBackground">@android:color/transparent</item>
        <!--設(shè)置窗口的背景是否為半透明,設(shè)置透明背景必須要設(shè)置此項-->
        <item name="android:windowIsTranslucent">true</item>
        <!--設(shè)置狀態(tài)欄的背景為半透明-->
        <item name="android:windowTranslucentStatus">true</item>
    </style>

第三,在AndroidManifest.xml指定的activity中設(shè)置主題樣式,例如:

<activity android:name=".MainActivity" android:theme="@style/TransparentTheme"/>
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容