Android Studio - ActionBar not displayed in the pr

2019-08-30 03:32发布

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.

2条回答
Summer. ? 凉城
2楼-- · 2019-08-30 04:10

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.

查看更多
Fickle 薄情
3楼-- · 2019-08-30 04:36

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

enter image description here

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

enter image description here

查看更多
登录 后发表回答