Studio报错 You need to use a Theme.AppCompat theme的两种解决办法
16lz
2021-01-25
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
法一:
当在AndroidManifest.xml文件的application的节点设置了属性:
android:theme="@android:style/Theme.NoTitleBar
而Activity继承了ActionBarActivity就回出现上述错误,解决的办法就是让Activity去继承Activity而不是ActionBarActivity
改完之后删掉报错的部分,然后别忘了导入Activity包
法二:
在AndroidMenifest.xml中加入一句:
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
例子:
<activity android:name="com.vmoksha.BaseActivity" android:label="@string/app_name" android:theme="@style/Theme.AppCompat.Light.NoActionBar" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>
然后在styles.xml中加入主题资源:
<style name="Theme.AppCompat.Light.NoActionBar" parent="@style/Theme.AppCompat.Light"> <item name="android:windowNoTitle">true</item> </style>
即可
更多相关文章
- 手把手带你搭建 Elasticsearch 集群
- Fragment 和 Activity 全通讯
- android学习记录(三) UI界面
- Android(安卓)studio中 RelativeLayout 的 layout_marginBottom
- Android(安卓)自定义View步骤
- 如何避免打开键盘或横竖屏切换,active重启,处理界面的延迟动画
- Singletons vs. Application Context in Android?
- Android解析网页响应xml格式文件的一种方法
- ListView@常用属性记录