Android中取消标题栏


第一种方法:
 在Activity的onCreate()中,在 setContentView()之前调用方法:
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉标题栏  
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,   
                WindowManager.LayoutParams.FLAG_FULLSCREEN);    //设置全屏
        
    setContentView();
                
第二种方法:

 在AndroidManifest.xml清单文件中,找到相应的Activity节点;
 <activity android:name=".MainActivity"
           android:theme="@android:style/Theme.NoTitleBar" />   ---- 去掉标题栏
           
 或者:
 <activity android:name=".SharedElementsAnimaton"
           android:theme="@android:style/Theme.NoTitleBar.Fullscreen" /> ---- 设置全屏
           
           
第三种方法:
以上两种方法都是针对单个的Activity,如果要使整个应用都没有标题栏,可以如下设置:
    在AndroidManifest.xml清单文件中,找到相应的application节点;
    <application
    ...
     android:theme="@android:style/Theme.NoTitleBar"  ---- 去掉标题栏
     ...   >
    application/>
    
    或者:
    <application
    ...
     android:theme="@android:style/Theme.NoTitleBar.Fullscreen"  ---- 设置全屏
     ...   >

    application/>



但是 ,某一天当我在一个程序中使用第二种方法时却导致程序在启动时崩溃了,是的,程序崩掉了。。。。把代码再回退到android:theme="@style/AppTheme"就没问题了,于是我就查一下,原来,在android:theme="@style/XXXX"还有其他的五种主题也可以取消标题栏:

android:theme="@style/Theme.Design.NoActionBar"
android:theme="@style/Theme.AppCompat.NoActionBar"
android:theme="@style/Theme.Design.Light.NoActionBar"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
android:theme="@style/Theme.AppCompat.DayNight.NoActionBar"


当我使用了android:theme="@style/Theme.Design.Light.NoActionBar"之后程序不会崩溃,而且是以没有标题栏(也没有actionBar)的样式显示。


至于这几种主题之间的区别现在还不是很理解,可以作为下一个知识点,学习之后再详细记录一下。





  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值