AppCompatActivity去掉标题

本文介绍了在Android应用中使用AppCompatActivity时去除标题栏和状态栏的多种方法。对于标题栏,可以通过在setContentView()前调用supportRequestWindowFeature()、修改AndroidManifest.xml文件中的配置或在setContentView()后隐藏ActionBar来实现。对于状态栏,可以采用请求窗口特性、设置主题属性或直接修改窗口参数的方法来隐藏。
1.当Activity继承AppCompatActivity时,去掉标题栏的方式有以下几种
方法1:
在setContentView()方法之前添加
supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
方法2. 有标题栏
<item name="windowNoTitle">false</item>
<item name="windowActionBar">true</item>

没有标题栏    
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>

没有标题栏
<item name="windowNoTitle">true</item>
<item name="windowActionBar">true</item>

会报错: AppCompat does not support the current theme features
<item name="windowNoTitle">false</item>
<item name="windowActionBar">false</item>

方法3:
在setContentView()之后
ActionBar actionBar = getSupportActionBar();
actionBar.hide();
 2.去掉状态栏
方法1:
requestWindowFeature(Window.FEATURE_NO_TITLE);    
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);

方法2:在主题中添加
<item name="android:windowFullscreen">true</item>

方法3:
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
getWindow().setAttributes(lp);
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值