使用Android Studio过程中遇到的一些问题总结

1、在使用Activity集成AppCompatActivity时

 首先引包老是出错,找不到AppCompatActivity,明明SDK下边有该包。这个错误发生在打开两个Android Studio时,关掉其中一个就正常了。

2、This Activity already has an action bar supplied by the window decor

 正常引入AppCompatActivity后,如果调用:

Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

 就会闪退,捕获异常发现错误是:

This Activity already has an action bar supplied by the window decor……

 查找到的解决方式:

 I think you're developing for Android Lollipop, but anyway include this line: <item name="windowActionBar">false</item> to your theme declaration inside of your app/src/main/res/values/styles.xml.
 Also, if you're using AppCompatActivity support library of version 22.1 or greater, add this line:
<item name="windowNoTitle">true</item>

 Your theme declaration may look like this after all these additions:

<!-- 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>
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 176,272评论 25 709
  • Correctness AdapterViewChildren Summary: AdapterViews can...
    MarcusMa阅读 12,877评论 0 6
  • afinalAfinal是一个android的ioc,orm框架 https://github.com/yangf...
    passiontim阅读 15,758评论 2 45
  • 文竹是一种很傲娇的植物。 不耐旱,需要持续保湿;性喜温暖,又忌阳光直射;好半阴通风,又不耐严寒。 而我们有时也会像...
    自愈学院阅读 2,675评论 0 0
  • 一开始我理解的杀熟是指做买卖的人专门卖高价给亲朋好友。卖给陌生人的价格反而低。 有一种关系是我越跟你好说话越难听。...
    五花肉不油腻阅读 2,944评论 0 0

友情链接更多精彩内容