Android异常-You need to use a Theme.AppCompat theme (or descendant) with this activity.
来源:互联网 发布:网络视频视听许可证 编辑:程序博客网 时间:2024/04/28 10:58
异常信息:
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
异常分析:
异常的意思是:你需要使用一个theme.appcompat主题(或后代)与此活动。
为什么会有这种情况出现,是因为Activity是继承的是AppCompatActivity,如下:
public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); }}
但是我使用的appTheme是普通Activity的Theme,所以会报错,让我使用继承theme.appcompat的主题(或后代)
<application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@android:style/Theme.NoTitleBar.Fullscreen"> <activity android:name=".MainActivity" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application>
异常解决:
第一种方法:改变主题,使主题继承于theme.appcompat.xxx
这是我们新建一个项目的时候,自动创建的一个AppTheme,注意看就是继承自Theme.AppCompat.xxx的
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <!-- Customize your theme here. --> <item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorAccent">@color/colorAccent</item> </style>
第二种方法:.改变类的继承父类 从AppCompatActivity 改为Activity
public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); }}
0 0
- Android异常-You need to use a Theme.AppCompat theme (or descendant) with this activity.
- 异常IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
- You need to use a Theme.AppCompat theme (or descendant) with this activity.异常处理其一
- Android开发~you need to use a theme.appcompat theme (or descendant) with this activity
- 【Android】You need to use a Theme.AppCompat theme (or descendant) with this activity解决方法
- Android Studio You need to use a Theme.AppCompat theme (or descendant) with this activity解决方法
- Android错误之:You need to use a Theme.AppCompat theme (or descendant) with this activity.
- Android Studio中报错 You need to use a Theme.AppCompat theme (or descendant) with this activity
- Android问题一:You need to use a Theme.AppCompat theme (or descendant) with this activity.
- Android--You need to use a Theme.AppCompat theme (or descendant) with this activity解决方案
- Android Studio: You need to use a Theme.AppCompat theme (or descendant) with this activity.
- Android 解决错误:You need to use a Theme.AppCompat theme (or descendant) with this activity
- Android issue: You need to use a Theme.AppCompat theme (or descendant) with this activity
- Android错误:You need to use a Theme.AppCompat theme (or descendant) with this activity.
- 关于“you need to use a theme.appcompat theme (or descendant) with this activity”错误
- You need to use a Theme.AppCompat theme (or descendant) with this activity
- You need to use a Theme.AppCompat theme (or descendant) with this activity解决方法
- You need to use a Theme.AppCompat theme (or descendant) with this activity.
- HDU 2058 The sum problem
- 连续子数组的最大和
- thinkcmf学习和开发经验总结
- SDUT OJ 3404 数据结构实验之排序七:选课名单
- JS事件流分析及兼容浏览器使用
- Android异常-You need to use a Theme.AppCompat theme (or descendant) with this activity.
- Android 沉浸式状态栏
- Subsets 子集和
- git在eclipse中的配置
- Android的R.drawable应用——制作NinePatch图片
- android 每个listview的item上都设置一个倒计时 而不错乱、卡顿的一个Demo
- Alcatraz的安装和使用
- sql/sqlite/sqlite3 创建和打开数据库
- classpath