在AS中运行程序时,设置隐藏title标签栏 -可以通过:
RequestWindowFeature(Window.FEATURE_NO_TITLE);
在同时使用requestWindowFeature()和setContentView()时,如果不注意顺序就会爆出如下错误:
Caused by: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
第一种情况:代码如下,这是因为两者使用顺序出错的缘故,可以通过字面意思了解就是requestFeature()的使用必须在前面。
setContentView(R.layout.main);
requestWindowFeature(Window.FEATURE_NO_TITLE);
第二种情况:本身顺序正确
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
这种情况可能是代码里的BaseActivity继承的是AppCompatActivity,但是requestWindownFeature(Window.FEATURE_NO_TITLE);是继承Activity中使用的,修改如下:
supportRequestWindowFeature(Window.FEATURE_NO_TITLE); //继承AppCompatActivity中使用
//requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
或者修改BaseActivity继承于Activity.
膜拜大佬,留下纪念~~