本文實(shí)例講述了Android編程實(shí)現(xiàn)播放視頻時(shí)切換全屏并隱藏狀態(tài)欄的方法。分享給大家供大家參考,具體如下:
1.
Demo示例:
@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {getWindow().getDecorView().setSystemUiVisibility(View.INVISIBLE); }else if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {// this.requestWindowFeature(Window.f);// 去掉標(biāo)題欄// this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,// WindowManager.LayoutParams.FLAG_FULLSCREEN);// 去掉信息欄Log.i("info", "portrait"); // 豎屏}設(shè)置:
<uses-sdk android:minSdkVersion="11" />
說(shuō)明:
View類(lèi)提供了setSystemUiVisibility和getSystemUiVisibility方法,這兩個(gè)方法實(shí)現(xiàn)對(duì)狀態(tài)欄的動(dòng)態(tài)顯示或隱藏的操作,以及獲取狀態(tài)欄當(dāng)前可見(jiàn)性。
setSystemUiVisibility(int visibility)方法可傳入的實(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ì)被隱藏。
2.
if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { WindowManager.LayoutParams attrs = getWindow().getAttributes(); attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN; getWindow().setAttributes(attrs); getWindow().addFlags( WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);} else if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { WindowManager.LayoutParams attrs = getWindow().getAttributes(); attrs.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN); getWindow().setAttributes(attrs); getWindow().clearFlags( WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);}希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注