Android Studio - ActionBar not displayed in the preview

孤街醉人 提交于 2019-12-11 18:38:46

问题


The ActionBar is visible when running the app on the device, however it is not in the preview section.

In the preview: https://i.stack.imgur.com/dNjAz.png

On the device: https://i.stack.imgur.com/IjIHn.png

This is the styles.xml

<!-- Base application theme. -->
<style name="Theme.AppTheme" parent="Base.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>

How can I make the ActionBar appear on the preview also? Thank you.


回答1:


I'm assuming you're using some sort of appcompat-v7:28.0.0-* version. I've just had the same problem. The solution for me was changing an implementation line in the build.gradle file (Module: app).

Replace this

implementation 'com.android.support:appcompat-v7:28.0.0-rc01' (or anything like this)

By this

implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'

According to this post, some appcompat-v7:28.0.0-* versions have a bug with "Design View" part of Android Studio.




回答2:


I dealt with the same problem and I think found a solution

  1. first open your layout editor window and click on the eye in the top left corner as shown below and then click on Show Layout Decorations

  1. You can change your apptheme there as well and so your toolbar, actionbar and so on...



来源:https://stackoverflow.com/questions/51089722/android-studio-actionbar-not-displayed-in-the-preview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!