android - 布局预览不显示 ActionBar 溢出选项

标签 android android-layout

我在这里遇到了一个小问题,ActionBar 的溢出选项显示在模拟器中,但没有显示在布局预览中。我目前正在使用 Android Studio v 2.1.3。

有没有人遇到同样的问题?

布局预览

enter image description here

模拟器截图

enter image description here

最佳答案

在布局文件中,添加 tools:menu直接归因于 Toolbar小部件:

<androidx.appcompat.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    tools:menu="@menu/your_menu"/>

根据docs :

tools:menu

Intended for: Any root <View>

This attribute specifies which menu the layout preview should show in the app bar. The value can be one or more menu IDs, separated by commas (without @menu/ or any such ID prefix and without the .xml extension).

但是,我发现它仅在以下情况下有效:

  1. 属性直接添加到Toolbar小部件
  2. 该值包括 @menu/前缀

关于android - 布局预览不显示 ActionBar 溢出选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39366258/

相关文章:

java - 获取一个字符串并在前面放置一个标准文本

android - 如何在 React Native 的文本上添加删除线?

android - android中UI控件的水平对齐

java - 在 Android 中的 Fragment 中使用 WebView 时,页面显示未格式化的文本

android - 连续旋转图像

java - 如何设置 relativelayout 高度等于它的宽度?

java - Recyclerview 更改适配器外部的项目颜色

android - 我如何将溢出菜单放在工具栏下方而不是溢出菜单与应用栏重叠

android - ScrollView 中的第一个嵌入式 ImageView 未显示

android - 如何为一个屏幕制作多个布局?