我使用的是android studio 1.1,新建项目后Activity继承ActionBarActivity,默认引用如下依赖:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.1.1'
}
按照以前在eclipse中的实现方式,我直接在onCreate方法中添加了如下的代码:
super.onCreate(savedInstanceState);//这个方法去掉也会报异常
this.requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉标题栏,去掉这一行,可以全屏,但还有标题栏存在
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);//去掉信息栏
会报如下的异常():
Caused by: java.lang.IllegalArgumentException: AppCompat does not support the current theme features
at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:360)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:246)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:106)
at com.shutup.think.myview.MainActivity.onCreate(MainActivity.java:17)
at android.app.Activity.performCreate(Activity.java:5249)
可以尝试的解决方案有:
- 添加如下自定义主题,同时修改manifest.xml中application节点的Theme
<style name="MyTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowFullscreen">true</item>
</style>
Activity中
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);//先调用,且不可删除
setContentView(R.layout.activity_main);
}
- 继承原始的Activity