Android app啟動(dòng)時(shí)黑屏或者白屏的原因及解決辦法
1、產(chǎn)生原因
其實(shí)顯示黑屏或者白屏實(shí)屬正常,這是因?yàn)檫€沒加載到布局文件,就已經(jīng)顯示了window窗口背景,黑屏白屏就是window窗口背景。
示例:

2、解決辦法
通過設(shè)置設(shè)置Style
(1)設(shè)置背景圖Theme
通過設(shè)置一張背景圖。 當(dāng)程序啟動(dòng)時(shí),首先顯示這張背景圖,避免出現(xiàn)黑屏
<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)設(shè)置透明Theme
通過把樣式設(shè)置為透明,程序啟動(dòng)后不會(huì)黑屏而是整個(gè)透明了,等到界面初始化完才一次性顯示出來
<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>
兩者對(duì)比:
Theme1 程序啟動(dòng)快,界面先顯示背景圖,然后再刷新其他界面控件。給人刷新不同步感覺。
Theme2 給人程序啟動(dòng)慢感覺,界面一次性刷出來,刷新同步。
(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顯示為對(duì)話框模式
android:theme="@android:style/Theme.NoTitleBar" //不顯示應(yīng)用程序標(biāo)題欄
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" //不顯示應(yīng)用程序標(biāo)題欄,并全屏
android:theme="Theme.Light " //背景為白色
android:theme="Theme.Light.NoTitleBar" //白色背景并無標(biāo)題欄
android:theme="Theme.Light.NoTitleBar.Fullscreen" //白色背景,無標(biāo)題欄,全屏
android:theme="Theme.Black" //背景黑色
android:theme="Theme.Black.NoTitleBar" //黑色背景并無標(biāo)題欄
android:theme="Theme.Black.NoTitleBar.Fullscreen" //黑色背景,無標(biāo)題欄,全屏
android:theme="Theme.Wallpaper" //用系統(tǒng)桌面為應(yīng)用程序背景
android:theme="Theme.Wallpaper.NoTitleBar" //用系統(tǒng)桌面為應(yīng)用程序背景,且無標(biāo)題欄
android:theme="Theme.Wallpaper.NoTitleBar.Fullscreen" //用系統(tǒng)桌面為應(yīng)用程序背景,無標(biāo)題欄,全屏
android:theme="Theme.Translucent" //透明背景
android:theme="Theme.Translucent.NoTitleBar" //透明背景并無標(biāo)題
android:theme="Theme.Translucent.NoTitleBar.Fullscreen" //透明背景并無標(biāo)題,全屏
android:theme="Theme.Panel " //面板風(fēng)格顯示
android:theme="Theme.Light.Panel" //平板風(fēng)格顯示
以上就是對(duì)Android app啟動(dòng)時(shí)黑屏或者白屏的原因及解決辦法的資料整理,后續(xù)繼續(xù)補(bǔ)充相關(guān)資料,謝謝大家對(duì)本站的支持!
- 完美解決Android App啟動(dòng)頁有白屏閃過的問題
- Android啟動(dòng)頁出現(xiàn)白屏、黑屏的解決方案
- Android啟動(dòng)APP時(shí)黑屏白屏的解決方法
- Flutter Android端啟動(dòng)白屏問題的解決
- 如何正確實(shí)現(xiàn)Android啟動(dòng)屏畫面的方法(避免白屏)
- 解決Android應(yīng)用冷啟動(dòng)時(shí)出現(xiàn)的白屏問題的方法
- Android的App啟動(dòng)時(shí)白屏的問題解決辦法
- Android中Splash應(yīng)用啟動(dòng)白屏問題的解決方法
- Android中使用Theme來解決啟動(dòng)app時(shí)出現(xiàn)的空白屏問題
- Android Splash界面白屏、黑屏問題的解決方法
- Android編程中activity啟動(dòng)時(shí)出現(xiàn)白屏、黑屏問題的解決方法
- Android 啟動(dòng)頁白屏解決方案
相關(guān)文章
android中AutoCompleteTextView的簡(jiǎn)單用法(實(shí)現(xiàn)搜索歷史)
本篇文章主要介紹了android中AutoCompleteTextView的簡(jiǎn)單用法(自動(dòng)提示),有需要的可以了解一下。2016-11-11
Android程序開發(fā)之ListView 與PopupWindow實(shí)現(xiàn)從左向右滑動(dòng)刪除功能
這篇文章主要介紹了Android程序開發(fā)之ListView 與PopupWindow實(shí)現(xiàn)滑動(dòng)刪除功能的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-07-07
RecyclerView實(shí)現(xiàn)仿支付寶應(yīng)用管理
這篇文章主要為大家詳細(xì)介紹了RecyclerView實(shí)現(xiàn)仿支付寶應(yīng)用管理的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-04-04
Android webview如何加載HTML,CSS等語言的示例
本篇文章主要介紹了Android webview如何加載HTML,CSS等語言的示例,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-11-11
Android自定義Camera實(shí)現(xiàn)拍照功能
這篇文章主要為大家詳細(xì)介紹了Android自定義Camera實(shí)現(xiàn)拍照功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-05-05
Android實(shí)現(xiàn)一個(gè)完美的倒計(jì)時(shí)功能
在Adroid應(yīng)用中,倒計(jì)時(shí)的功能使用的很多,例如點(diǎn)擊獲取短信驗(yàn)證碼之后的倒計(jì)時(shí)等等,這篇文章主要給大家介紹了關(guān)于利用Android如何實(shí)現(xiàn)一個(gè)完美的倒計(jì)時(shí)功能的相關(guān)資料,需要的朋友可以參考下2021-11-11
Android Color顏色過度計(jì)算實(shí)現(xiàn)代碼
這篇文章主要介紹了Android Color顏色過度計(jì)算實(shí)現(xiàn)代碼的相關(guān)資料,需要的朋友可以參考下2017-06-06
Android使用socket創(chuàng)建簡(jiǎn)單TCP連接的方法
這篇文章主要介紹了Android使用socket創(chuàng)建簡(jiǎn)單TCP連接的方法,結(jié)合實(shí)例形式詳細(xì)分析了Android使用socket創(chuàng)建TCP連接的具體步驟與實(shí)現(xiàn)技巧,需要的朋友可以參考下2016-04-04
Android使用URL讀取網(wǎng)絡(luò)資源的方法
這篇文章主要為大家詳細(xì)介紹了Android使用URL讀取網(wǎng)絡(luò)資源的方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-10-10

