国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android app啟動時黑屏或者白屏的原因及解決辦法

2019-12-12 05:12:13
字體:
來源:轉載
供稿:網友

1、產生原因

其實顯示黑屏或者白屏實屬正常,這是因為還沒加載到布局文件,就已經顯示了window窗口背景,黑屏白屏就是window窗口背景。

示例:

2、解決辦法

通過設置設置Style

(1)設置背景圖Theme

通過設置一張背景圖。 當程序啟動時,首先顯示這張背景圖,避免出現黑屏

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">    <item name="android:screenOrientation">portrait</item>    <item name="android:windowBackground">>@mipmap/splash</item>    <item name="android:windowIsTranslucent">true</item>    <item name="android:windowNoTitle">true</item></style> 

(2)設置透明Theme

通過把樣式設置為透明,程序啟動后不會黑屏而是整個透明了,等到界面初始化完才一次性顯示出來

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">    <item name="android:windowNoTitle">true</item>    <item name="android:windowBackground">@android:color/transparent</item>    <item name="android:windowIsTranslucent">true</item>    <item name="android:screenOrientation">portrait</item>  </style>

兩者對比:

Theme1 程序啟動快,界面先顯示背景圖,然后再刷新其他界面控件。給人刷新不同步感覺。
Theme2 給人程序啟動慢感覺,界面一次性刷出來,刷新同步。 

(3)修改AndroidManifest.xml

<application    android:name=".App"    android:allowBackup="true"    android:icon="@mipmap/ic_launcher"    android:label="@string/app_name"    android:supportsRtl="true">    <activity android:name=".MainActivity"     android:theme="@style/AppTheme">      <intent-filter>        <action android:name="android.intent.action.MAIN" />        <category android:name="android.intent.category.LAUNCHER" />      </intent-filter>    </activity>  //......</application>

解決后示例:

3、常見的Theme主題

android:theme="@android:style/Theme.Dialog" //Activity顯示為對話框模式

android:theme="@android:style/Theme.NoTitleBar" //不顯示應用程序標題欄

android:theme="@android:style/Theme.NoTitleBar.Fullscreen" //不顯示應用程序標題欄,并全屏

android:theme="Theme.Light " //背景為白色

android:theme="Theme.Light.NoTitleBar" //白色背景并無標題欄

android:theme="Theme.Light.NoTitleBar.Fullscreen" //白色背景,無標題欄,全屏

android:theme="Theme.Black" //背景黑色

android:theme="Theme.Black.NoTitleBar" //黑色背景并無標題欄

android:theme="Theme.Black.NoTitleBar.Fullscreen" //黑色背景,無標題欄,全屏

android:theme="Theme.Wallpaper" //用系統桌面為應用程序背景

android:theme="Theme.Wallpaper.NoTitleBar" //用系統桌面為應用程序背景,且無標題欄

android:theme="Theme.Wallpaper.NoTitleBar.Fullscreen" //用系統桌面為應用程序背景,無標題欄,全屏

android:theme="Theme.Translucent" //透明背景

android:theme="Theme.Translucent.NoTitleBar" //透明背景并無標題

android:theme="Theme.Translucent.NoTitleBar.Fullscreen" //透明背景并無標題,全屏

android:theme="Theme.Panel " //面板風格顯示

android:theme="Theme.Light.Panel" //平板風格顯示

以上就是對Android app啟動時黑屏或者白屏的原因及解決辦法的資料整理,后續繼續補充相關資料,謝謝大家對本站的支持!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 两当县| 塔城市| 酒泉市| 福泉市| 曲阳县| 临桂县| 松阳县| 寿宁县| 子长县| 新闻| 略阳县| 洛川县| 沙坪坝区| 广州市| 凌云县| 商河县| 镇坪县| 华安县| 山丹县| 宁远县| 温州市| 商南县| 木兰县| 泸州市| 台东县| 桂平市| 柯坪县| 广丰县| 湘乡市| 龙山县| 称多县| 花莲县| 平邑县| 舞阳县| 乌海市| 漾濞| 姜堰市| 恭城| 林西县| 永康市| 钟祥市|