Android Studio - ActionBar not displayed in the pr

2019-08-30 03:35发布

问题:

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...