Android开发——去掉系统自带标题栏的几种方式

    今天在练习自定义标题栏(Android初级开发(四)——补充3)的过程当中遇到了隐藏系统自带标题栏的问题,现将几种去掉系统自带标题栏的方式作一总结。大致上能够分为两种方式,一种是修改xml文件(这种方式产生的效果做用于全部Activity),一种是编码实现(这种方式产生的效果只做用于当前Activity):android

    方法1-1:app

    一、查看清单文件AndroidManifest.xml中的themethis

    android:theme="@style/AppTheme"(系统默认的) 保持不变编码

    二、在style.xml文件中修改AppThemespa

    



    方法1-2    xml

    在清单文件AndroidManifest.xml中修改theme,使用系统自带的无标题样式blog

    实现无标题栏(但有系统自带的任务栏)继承

    android:theme = "@android:style/Theme.NoTitleBar开发

    实现全屏效果:get

    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" 平板风格显示


   业精于勤荒于嬉,行成于思毁于随