設置activity無標題欄
1.設置清單文件主題樣式如下
<application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".Main" android:theme="@android:style/Theme.DeviceDefault.NoActionBar <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> 在activity里設置android:theme="@android:style/Theme.DeviceDefault.NoActionBar
2.設置java代碼繼承類
public class Main extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } } 把當前繼承的AppCompatActivity類換成Activity 如下: public class Main extends Activity
3.樣式大全
Theme.Dialog : (圖1)Activity顯示為對話框模式 Theme.NoTitleBar : (圖2)不顯示應用程序標題欄 Theme.NoTitleBar.Fullscreen : (圖3)不顯示應用程序標題欄,並全屏 Theme.Light : (圖4)背景為白色 Theme.Light.NoTitleBar : (圖5)白色背景並無標題欄 Theme.Light.NoTitleBar.Fullscreen : (圖6)白色背景,無標題欄,全屏 Theme.Black : (圖7)背景黑色 Theme.Black.NoTitleBar : (圖8)黑色背景並無標題欄 Theme.Black.NoTitleBar.Fullscreen : (圖9)黑色背景,無標題欄,全屏 Theme.Wallpaper : (圖10)用系統桌面為應用程序背景 Theme.Wallpaper.NoTitleBar : (圖11) 用系統桌面為應用程序背景,且無標題欄 Theme.Wallpaper.NoTitleBar.Fullscreen : (圖12)用系統桌面為應用程序背景,無標題欄,全屏 Theme.Translucent : (圖13)透明背景 Theme.Translucent.NoTitleBar : (圖14)透明背景並無標題 Theme.Translucent.NoTitleBar.Fullscreen : (圖15)透明背景並無標題,全屏 Theme.Panel : (圖16)面板風格顯示 Theme.Light.Panel : (圖17)平板風格顯示
一、通過Java代碼
在setContentView之前執行: requestWindowFeature(Window.FEATURE_NO_TITLE);//隱藏標題欄 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);//隱藏狀態欄
二、調用Android自帶的Theme
直接在AndroidManifest.xml中需要全屏顯示的Activity屬性中添加 android:theme="@android:style/Theme.NoTitleBar.Fullscreen" // 不顯示應用程序標題欄,並全屏 android:theme="Theme.Light.NoTitleBar.Fullscreen" // 白色背景,無標題欄,全屏 android:theme="Theme.Black.NoTitleBar.Fullscreen" // 黑色背景,無標題欄,全屏
三、自己定義全屏Theme
在style.xml文件中定義theme(如果沒有style.xml,在res/values目錄下創建) <resources> <style name="Theme.NoTitle_FullScreen"> <!--自定義主題名稱--> <item name="android:windowNoTitle">true</item> <item name="android:windowFullscreen">true</item> </style> </resources>