Dialog全屏,去掉狀態(tài)欄的方式
dialog即使設(shè)置全屏了,但還是有狀態(tài)欄占用高度這;
直接將下面這行代碼放到你的dialog中即可
@Override protected void onStart() { super.onStart(); int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_FULLSCREEN; this.getWindow().getDecorView().setSystemUiVisibility(uiOptions); }
順便說(shuō)下自定義dialog寬高:
WindowManager.LayoutParams attributes = getWindow().getAttributes(); attributes.width = width; attributes.height = height; getWindow().setAttributes(attributes);
添加兩個(gè)基本的style
<!--普通dialog樣式--> <style name="customerDialog" parent="@android:style/Theme.Dialog"> <item name="android:windowFrame">@null</item> <item name="android:windowIsFloating">true</item> <item name="android:windowIsTranslucent">true</item> <item name="android:windowNoTitle">true</item> <item name="android:background">@android:color/transparent</item> <!-- <item name="android:windowAnimationStyle">@android:style/Animation.Translucent</item> --> <item name="android:windowBackground">@android:color/transparent</item> <item name="android:windowSoftInputMode">stateHidden|adjustPan</item> </style> <!--透明背景dialog樣式--> <style name="TransparentDialogStyle" parent="@android:style/Theme.Dialog"> <item name="android:windowBackground">@android:color/transparent</item> <item name="android:windowNoTitle">true</item> <item name="android:backgroundDimEnabled">false</item> </style>
補(bǔ)充知識(shí):Android關(guān)于全屏設(shè)置和隱藏狀態(tài)欄、沉浸式狀態(tài)欄的總結(jié)
1.全屏和推出全屏
實(shí)現(xiàn)全屏
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
有一個(gè)View.setLayoutparams的方法,注意這個(gè)LayoutParams跟的不是自身的LayoutParams而是父容器的layoutParams
退出全屏
final WindowManager.LayoutParams attrs = getWindow().getAttributes(); attrs.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN); getWindow().setAttributes(attrs); getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
2.隱藏狀態(tài)欄
getWindow().getDecorView().setSystemUiVisibility(View.INVISIBLE);
參數(shù):
View.SYSTEM_UI_FLAG_VISIBLE:顯示狀態(tài)欄,Activity不全屏顯示(恢復(fù)到有狀態(tài)的正常情況)。
View.INVISIBLE:隱藏狀態(tài)欄,同時(shí)Activity會(huì)伸展全屏顯示。
View.SYSTEM_UI_FLAG_FULLSCREEN:Activity全屏顯示,且狀態(tài)欄被隱藏覆蓋掉。
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN:Activity全屏顯示,但狀態(tài)欄不會(huì)被隱藏覆蓋,狀態(tài)欄依然可見(jiàn),Activity頂端布局部分會(huì)被狀態(tài)遮住。
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION:效果同View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
View.SYSTEM_UI_LAYOUT_FLAGS:效果同View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION:隱藏虛擬按鍵(導(dǎo)航欄)。有些手機(jī)會(huì)用虛擬按鍵來(lái)代替物理按鍵。
View.SYSTEM_UI_FLAG_LOW_PROFILE:狀態(tài)欄顯示處于低能顯示狀態(tài)(low profile模式),狀態(tài)欄上一些圖標(biāo)顯示會(huì)被隱藏。
3.沉浸式狀態(tài)欄(android4.4開(kāi)始引進(jìn))
(1).通過(guò)SystemBarTintManager
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { setTranslucentStatus(true); SystemBarTintManager tintManager = new SystemBarTintManager(this); tintManager.setStatusBarTintEnabled(true); tintManager.setStatusBarTintResource(R.color.color_top_bg);// 通知欄所需顏色 } @TargetApi(19) private void setTranslucentStatus(boolean on) { Window win = getWindow(); WindowManager.LayoutParams winParams = win.getAttributes(); final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS; // WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION if (on) { winParams.flags |= bits; } else { winParams.flags &= ~bits; } win.setAttributes(winParams); }
(2).通過(guò)頂部增加同ActionBar顏色的view(如果設(shè)置后出現(xiàn)tittlebar則在清單文件里面配置activity的style為NoTittlebar)
Window window = getWindow(); window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); ViewGroup decorView = (ViewGroup) window.getDecorView(); view = new View(this); view.setLayoutParams(new ViewGroup.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, getStatusBarHeight(this))); view.setBackgroundColor(getResources().getColor(R.color.color_top_bg)); decorView.addView(view);
以上這篇Dialog全屏,去掉狀態(tài)欄的方式就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Android實(shí)現(xiàn)毛玻璃效果彈出菜單動(dòng)畫(huà)
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)毛玻璃效果彈出菜單動(dòng)畫(huà),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-08-08android實(shí)現(xiàn)banner輪播圖無(wú)限輪播效果
這篇文章主要為大家詳細(xì)介紹了android實(shí)現(xiàn)banner輪播圖無(wú)限輪播效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-10-10Android 6.0動(dòng)態(tài)權(quán)限申請(qǐng)教程
本文主要介紹了Android 6.0動(dòng)態(tài)權(quán)限申請(qǐng)的教程,具有很好的參考價(jià)值。下面跟著小編一起來(lái)看下吧2017-03-03Android中ListView下拉刷新的實(shí)現(xiàn)代碼
這篇文章主要介紹了Android中ListView下拉刷新的實(shí)現(xiàn)代碼的相關(guān)資料,需要的朋友可以參考下2017-06-06Android ListView用EditText實(shí)現(xiàn)搜索功能效果
本篇文章主要介紹了Android ListView用EditText實(shí)現(xiàn)搜索功能效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下。2017-03-03Android重復(fù)引用多個(gè)場(chǎng)景報(bào)錯(cuò)的問(wèn)題解決
本文主要介紹了Android重復(fù)引用多個(gè)場(chǎng)景報(bào)錯(cuò)的問(wèn)題解決,主要介紹了5種情況,具有一定的參考價(jià)值,感興趣的可以了解一下2024-03-03Android 文件存儲(chǔ)與SharedPreferences存儲(chǔ)方式詳解用法
SharedPreferences是安卓平臺(tái)上一個(gè)輕量級(jí)的存儲(chǔ)類(lèi),用來(lái)保存應(yīng)用的一些常用配置,比如Activity狀態(tài),Activity暫停時(shí),將此activity的狀態(tài)保存到SharedPereferences中;當(dāng)Activity重載,系統(tǒng)回調(diào)方法onSaveInstanceState時(shí),再?gòu)腟haredPreferences中將值取出2021-10-10