Android开发去除标题栏title



一、Android开发去除标题栏title其实非常简单,他有两种方法,一种是在代码中添加,另一种是在AndroidManifest.xml中添加:

1、在代码中实现
在此方法setContentView(R.layout.main)之前加入:requestWindowFeature(Window.FEATURE_NO_TITLE);标题栏就没有了。

2、在AndroidManifest.xml中实现
注册Activity时加上如下一句配置就可以实现。
<activity  android:name=".Activity"  android:theme="@android:style/Theme.NoTitleBar"> </activity>


二、requestWindowFeature(Window.FEATURE_NO_TITLE)无效解决方法:
正常情况下requestWindowFeature(Window.FEATURE_NO_TITLE)是可以生效的,但是当Activity继承子AppCompatActivity的时候,这个就失效了
解决办法:

1、手动在oncreate里调用hide()
if (getSupportActionBar() != null){
   getSupportActionBar().hide();
}


2、第二种:用supportrequestwindowFeature设置
   supportRequestWindowFeature(Window.FEATURE_NO_TITLE);

  
3、第三种:直接修改style ,缺点是直接全局都无Title了(注意继承)
   <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
      <!-- Customize your theme here. -->
      <item name="colorPrimary">@color/colorPrimary</item>
      <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
      <item name="colorAccent">@color/colorAccent</item>
      <item name="android:windowActionBar">false</item>
      <item name="android:windowNoTitle">true</item>
   </style>

  
4、第四种:  对应的Activity 注册中:

添加 android:theme="@style/Theme.AppCompat.NoActionBar"

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值