您的位置:首页 > 移动开发

错误:You need to use a Theme.AppCompat theme (or descendant) with this activity.

2016-07-02 06:52 701 查看
 错误提示:07-01 00:42:39.109: E/AndroidRuntime(17157): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android_007_dialogtest/com.example.android_007_dialogtest.MainActivity}:
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
问题出现的原因:
想要设置APP的显示规则,即设置activity全屏显示,代码如下:

[html] view
plain copy

 





<activity  

    android:name=".MainActivity"  

    android:theme="@android:style/Theme.NoTitleBar.Fullscreen"  

    android:label="@string/app_name" >  

原因:
           从错误提示中提到Theme.AppCompat theme,这是因为我们的activity继承了兼容包中的类,比如我这里就无意中继承了ActionBarActivity,它来自android.support.v7.app.ActionBarActivity。所以就要使用与其配合的AppCompat的theme才行。

解决:

解决方法1.将MainActivity.java中的主类继承方式修改,即将继承自ActionBarActivity类,修改直接继承Activity。则问题可解,如下图所示,修改此处内容为Activity



[align=left] [/align]

解决方法2.根据提示来配合使用AppCompat中的theme,如下:

[html] view
plain copy

 





<activity  

    android:name=".MainActivity"  

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

    android:label="@string/app_name" >  

 

以上就是解决You need to use a Theme.AppCompat theme (or descendant) with this activity.的两种方法
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: