Android中隱藏狀態(tài)欄和標(biāo)題欄的方法匯總(隱藏狀態(tài)欄、標(biāo)題欄的五種方法)
方法一:
public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // 隱藏標(biāo)題欄 requestWindowFeature(Window.FEATURE_NO_TITLE); // 隱藏狀態(tài)欄 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.activity_main); } }
方法二:
<!-- 同時(shí)隱藏狀態(tài)欄和標(biāo)題欄 --> <activity android:name="com.ysj.demo.MainActivity" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>
方法三:
<!-- Application theme. --> <style name="AppTheme" parent="AppBaseTheme"> <!-- All customizations that are NOT specific to a particular API-level can go here. --> <!-- 隱藏狀態(tài)欄 --> <item name="android:windowFullscreen">true</item> <!-- 隱藏標(biāo)題欄 --> <item name="android:windowNoTitle">true</item> </style>
方法四:動(dòng)態(tài)顯示隱藏狀態(tài)欄
//隱藏狀態(tài)欄 WindowManager.LayoutParams lp = context.getWindow().getAttributes(); lp.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN; context.getWindow().setAttributes(lp); //顯示狀態(tài)欄 WindowManager.LayoutParams attr = context.getWindow().getAttributes(); attr.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN); context.getWindow().setAttributes(attr);
方法五:動(dòng)態(tài)顯示隱藏狀態(tài)欄
View類提供了setSystemUiVisibility和getSystemUiVisibility方法,這兩個(gè)方法實(shí)現(xiàn)對(duì)狀態(tài)欄的動(dòng)態(tài)顯示或隱藏的操作,以及獲取狀態(tài)欄當(dāng)前可見性。
setSystemUiVisibility方法傳入的實(shí)參分析:
setSystemUiVisibility(int visibility)方法可傳入的實(shí)參為:
1. View.SYSTEM_UI_FLAG_VISIBLE:顯示狀態(tài)欄,
Activity不全屏顯示(恢復(fù)到有狀態(tài)的正常情況)。
2. View.INVISIBLE:隱藏狀態(tài)欄,同時(shí)Activity會(huì)伸展全屏顯示。
3. View.SYSTEM_UI_FLAG_FULLSCREEN:Activity全屏顯示,且狀態(tài)欄被隱藏覆蓋掉。
4. View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN:Activity全屏顯示,但狀態(tài)欄不會(huì)被隱藏覆蓋,狀態(tài)欄依然可見,Activity頂端布局部分會(huì)被狀態(tài)遮住。
5. View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION:效果同View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
6. View.SYSTEM_UI_LAYOUT_FLAGS:效果同View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
7. View.SYSTEM_UI_FLAG_HIDE_NAVIGATION:隱藏虛擬按鍵(導(dǎo)航欄)。有些手機(jī)會(huì)用虛擬按鍵來(lái)代替物理按鍵。
8. View.SYSTEM_UI_FLAG_LOW_PROFILE:狀態(tài)欄顯示處于低能顯示狀態(tài)(low profile模式),狀態(tài)欄上一些圖標(biāo)顯示會(huì)被隱藏。
package com.administrator.statubarapplication; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.LinearLayout; import android.widget.TextView; public class MainActivity extends Activity implements View.OnClickListener { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); assignViews(); setOnClicks(); } private void setOnClicks() { mButton1.setOnClickListener(this); mButton2.setOnClickListener(this); mButton3.setOnClickListener(this); mButton4.setOnClickListener(this); mButton5.setOnClickListener(this); mButton6.setOnClickListener(this); mButton7.setOnClickListener(this); } private LinearLayout mMain; private TextView mTextview; private Button mButton1; private Button mButton2; private Button mButton3; private Button mButton4; private Button mButton5; private Button mButton6; private Button mButton7; private void assignViews() { mMain = (LinearLayout) findViewById(R.id.main); mTextview = (TextView) findViewById(R.id.textview); mButton1 = (Button) findViewById(R.id.button1); mButton2 = (Button) findViewById(R.id.button2); mButton3 = (Button) findViewById(R.id.button3); mButton4 = (Button) findViewById(R.id.button4); mButton5 = (Button) findViewById(R.id.button5); mButton6 = (Button) findViewById(R.id.button6); mButton7 = (Button) findViewById(R.id.button7); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.button1: //Activity全屏顯示,且狀態(tài)欄被隱藏覆蓋掉 mMain.setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN); mTextview.setText("Activity全屏顯示,且狀態(tài)欄被隱藏覆蓋掉\nView.SYSTEM_UI_FLAG_FULLSCREEN"); break; case R.id.button2: mMain.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE); mTextview.setText("恢復(fù)到有狀態(tài)的正常情況\nView.SYSTEM_UI_FLAG_VISIBLE"); break; case R.id.button3: mMain.setSystemUiVisibility(View.INVISIBLE); mTextview.setText("http://隱藏狀態(tài)欄,同時(shí)Activity會(huì)伸展全屏顯示\nView.INVISIBLE"); break; case R.id.button4: mMain.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); mTextview.setText("Activity全屏顯示,但狀態(tài)欄不會(huì)被隱藏覆蓋,狀態(tài)欄依然可見,Activity頂端布局部分會(huì)被狀態(tài)遮\nView" + ".SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN \n View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION"); break; case R.id.button5: mMain.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); mTextview.setText("Activity全屏顯示,狀態(tài)欄透明\nView.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION"); break; case R.id.button6: mMain.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION); mTextview.setText("隱藏虛擬按鍵\nView.SYSTEM_UI_FLAG_HIDE_NAVIGATION"); break; case R.id.button7: mMain.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE); mTextview.setText("狀態(tài)欄低能顯示,有一些會(huì)被隱藏\nView.SYSTEM_UI_FLAG_LOW_PROFILE"); break; default: break; } } }
下面看下 隱藏標(biāo)題欄和底部操作欄,可上下滑動(dòng)顯示代碼
@Override public void onWindowFocusChanged(boolean hasFocus) { super.onWindowFocusChanged(hasFocus); if (hasFocus) { View decorView = that.getWindow().getDecorView(); decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_FULLSCREEN); } }
以上所述是小編給大家介紹的Android中隱藏狀態(tài)欄和標(biāo)題欄的方法匯總(隱藏狀態(tài)欄、標(biāo)題欄的五種方法),希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
- Android中自定義標(biāo)題欄樣式的兩種方法
- 3種Android隱藏頂部狀態(tài)欄及標(biāo)題欄的方法
- Android自定義狀態(tài)欄顏色與應(yīng)用標(biāo)題欄顏色一致
- Android 頂部標(biāo)題欄隨滑動(dòng)時(shí)的漸變隱藏和漸變顯示效果
- Android中去掉標(biāo)題欄的幾種方法(三種)
- Android 全屏無(wú)標(biāo)題欄的三種實(shí)現(xiàn)方法
- Android中隱藏標(biāo)題欄和狀態(tài)欄的方法
- Android 使用CoordinatorLayout實(shí)現(xiàn)滾動(dòng)標(biāo)題欄效果的實(shí)例
- Android ScrollView滑動(dòng)實(shí)現(xiàn)仿QQ空間標(biāo)題欄漸變
- Android實(shí)現(xiàn)可折疊式標(biāo)題欄
相關(guān)文章
Android實(shí)現(xiàn)隨手指移動(dòng)小球
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)隨手指移動(dòng)小球,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-08-08詳解Android提交數(shù)據(jù)到服務(wù)器的兩種方式四種方法
本篇文章主要介紹了Android提交數(shù)據(jù)到服務(wù)器的兩種方式四種方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下。2016-11-11Android編程設(shè)計(jì)模式之責(zé)任鏈模式詳解
這篇文章主要介紹了Android編程設(shè)計(jì)模式之責(zé)任鏈模式,詳細(xì)分析了Android設(shè)計(jì)模式中責(zé)任鏈模式的概念、原理、應(yīng)用場(chǎng)景、使用方法及相關(guān)操作技巧,需要的朋友可以參考下2017-12-12android異步請(qǐng)求服務(wù)器數(shù)據(jù)示例
這篇文章主要介紹了android異步請(qǐng)求服務(wù)器數(shù)據(jù)示例,需要的朋友可以參考下2014-03-03Flutter構(gòu)建自定義Widgets的全過(guò)程記錄
在Flutter實(shí)際開發(fā)中,大家可能會(huì)遇到flutter框架中提供的widget達(dá)不到我們想要的效果,這時(shí)就需要我們?nèi)プ远xwidget,下面這篇文章主要給大家介紹了關(guān)于Flutter構(gòu)建自定義Widgets的相關(guān)資料,需要的朋友可以參考下2022-01-01android項(xiàng)目手機(jī)衛(wèi)士來(lái)電顯示號(hào)碼歸屬地
由于詐騙電話越來(lái)越猖狂,號(hào)碼歸屬地顯示越來(lái)越重要,本篇文章主要介紹了android手機(jī)衛(wèi)士來(lái)電顯示號(hào)碼歸屬地,有要的朋友可以了解一下。2016-10-10Android應(yīng)用的Material設(shè)計(jì)中圖片的相關(guān)處理指南
這篇文章主要介紹了Android應(yīng)用的Material設(shè)計(jì)中圖片的相關(guān)處理指南,除了介紹新的方法外文中還給出了一些設(shè)計(jì)標(biāo)準(zhǔn)樣例僅供參考,需要的朋友可以參考下2016-04-04詳解Retrofit2.0 公共參數(shù)(固定參數(shù))
這篇文章主要介紹了Retrofit2.0 公共參數(shù)(固定參數(shù)),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-04-04