我正忙着尝试实现支持库,以便我可以使用 AppCompatActivty
据我所知,我把所有东西都放在了正确的地方。但我仍然收到错误。
样式.xml
<resources>
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>
v21/styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppBaseTheme" parent="Theme.AppCompat.Light"></style>
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>
list .xml
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher_on"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
Activity .java
public class RegisterActivity extends AppCompatActivity
现在,当我运行我的应用程序并尝试打开 RegisterActivty
时,我收到以下错误。
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.tuta_me/activities.RegisterActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
我一定是漏掉了什么地方。我做错了什么?
最佳答案
添加这个
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
</style>
在您的 v21/styles.xml 文件中。没有它,<style name="AppTheme" parent="AppBaseTheme">
没有任何意义。
关于java - 您需要使用 Theme.AppCompat 主题错误,即使主题设置为 AppCompat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34370737/