https://blog.csdn.net/qq_28585471/article/details/75991613
今天在練習自定義標題欄(Android初級開發(四)——補充3)的過程中遇到了隱藏系統自帶標題欄的問題,現將幾種去掉系統自帶標題欄的方式做一總結。大體上可以分為兩種方式,一種是修改xml文件(這種方式產生的效果作用於所有Activity),一種是編碼實現(這種方式產生的效果只作用於當前Activity):
方法1-1:
1、查看清單文件AndroidManifest.xml中的theme
android:theme="@style/AppTheme"(系統默認的) 保持不變
2、在style.xml文件中修改AppTheme

方法1-2
在清單文件AndroidManifest.xml中修改theme,使用系統自帶的無標題樣式
實現無標題欄(但有系統自帶的任務欄)
android:theme = "@android:style/Theme.NoTitleBar
實現全屏效果:
android:theme = "@android:style/Theme.NoTitleBar.Fullscreen"
!!!這時,可能會有朋友發現自己運行后出現錯誤,提示You need to use a Theme.AppCompat theme (or descendant) with this activity.這是因為Activity繼承自了android.support.v7.app.AppCompatActivity,而不是android.app.Activity。具體的解決方法有兩種:
1)如果不是強烈要求我們的Activity必須繼承自AppCompatActivity,就直接讓它繼承Activity.如圖

2)如果還是想繼承自AppCompatActivity,那么根據提示來使用AppCompat的theme,即將AndroidManifest.xml文件中關於Activity的theme配置改為:
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
好了,運行程序,你會發現問題已經解決啦~!!
方式1-3
在清單文件AndroidManifest.xml中修改theme,使用自定義的無標題樣式
android:theme = "@style/NoTitle"
在res/values/styles.xml文件中,加入如下代碼
<style name="NoTitle"> <item name="android:windowNoTitle">true</item> </style>
方法2
在程序中編寫代碼進行設置,只需在onCreate()方法中加入如下代碼:
實現無標題欄(但有系統自帶的任務欄)
requestWindowFeature(Window.FEATURE_NO_TITLE);
實現全屏效果
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
我在參考其他小伙伴的隱藏標題欄相關資料時,發現很多人都喜歡在文章最后附上這個Android系統自帶樣式羅列表,本來我是不打算仿照他們的這個做法的,但是想着還是自己敲一遍加深印象,抱着這個目的,下面請見Android系統自帶樣式:)
附:Android系統自帶樣式
android:theme = "@android:style/Theme.Dialog" 將一個Activity顯示為對話框模式
android:theme = "@android:style/Theme.NoTitleBar" 不顯示應用程序標題欄
android:theme = "@android:style/Theme.NoTitleBar.Fullscreen" 不顯示應用程序標題欄,並全屏
android:theme = "Theme.Light" 背景為白色
andorid:theme = "Theme.Light.NoTitleBar" 白色背景並無標題欄
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 = "Translucent" 透明背景
android:theme = "Theme.Translucent.NoTitleBar" 透明背景並無標題
android:theme = "Theme.Translucent.NoTitleBar.Fullscreen" 透明背景並無標題,全屏
android:theme = "Theme.Panel" 面板風格顯示
android:theme = "Theme.Light.Panel" 平板風格顯示
