AppCompatActivity去掉标题

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);

猜你喜欢

转载自blog.csdn.net/ronadlo7/article/details/81032878