Android Studio - ActionBar未在预览中显示

问题描述 投票:0回答:2

在设备上运行应用程序时,ActionBar可见,但它不在预览部分中。

在预览中:https://i.stack.imgur.com/dNjAz.png

在设备上:https://i.stack.imgur.com/IjIHn.png

这是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>

如何让ActionBar也出现在预览中?谢谢。

android android-actionbar
2个回答
1
投票

我假设你正在使用某种appcompat-v7:28.0.0-*版本。我刚遇到同样的问题。我的解决方案是更改build.gradle文件(Module:app)中的实现行。

替换它

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

这样

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

根据this的帖子,一些appcompat-v7:28.0.0-*版本有一个Android Studio的“设计视图”部分的错误。


1
投票

我处理同样的问题,我认为找到了解决方案

  1. 首先打开布局编辑器窗口,然后单击左上角的眼睛,如下所示,然后单击Show Layout Decorations

enter image description here

  1. 您也可以在那里更改您的apptheme,以及您的工具栏,操作栏等等...

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.