10. You need to use a Theme.AppCompat theme (or descendant) with this activity
来源:互联网 发布:镇江市迈越网络 编辑:程序博客网 时间:2024/06/02 17:53
如上图所示,用AS仿做微信界面,自定义 actionBar时出了错误。
错误内容:
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
代码展示:
自己定义的样式:
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar"> <item name="android:actionOverflowButtonStyle">@style/weixinActionOverflowButtonStyle</item> </style> <style name="weixinActionOverflowButtonStyle"> <item name="android:src">@drawable/actionbar_add_icon</item> </style>
这一段没有问题,主要是原先的系统默认样式为:
style.xml <!-- Base application theme. --> <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>
main.javapublic class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);
错误原因:
(截图来源于stackoverflow)
原因是你想要使用的样式是继承于 ActionBarActivity,可是原本要求的样式应该继承于 AppCompat
修改方法:
将 main.java 文件中的class 继承于 Activity即可!(如下:)
public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);
0 0
- 10. 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
- 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解决方法
- 【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.
- 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.
- Android Studio 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的问题
- SQL JOIN 优化
- 计时
- Java虚拟机的内存组成以及堆内存介绍
- Android Studio Error:(1, 1) 错误: 非法字符: \65279
- python爬虫解析json数据报错(unicode error) 'utf-8' codec can't decode byte 0xbb in position 0
- 10. You need to use a Theme.AppCompat theme (or descendant) with this activity
- Android(Java)利用findbugs进行代码静态检查
- 需求:使用SwipeRefreshLayout时,在界面顶部才执行刷新
- 人工智能
- Openstack_SQLAlchemy_一对多关系表的多表插入实现
- Linux文件系统操作命令
- Java 项目优化实战
- Classes and Structures
- UVa - 514 - Rails(栈-stack)