布局预览不显示ActionBar溢出选项 [英] Layout preview not showing ActionBar overflow options

查看:109
本文介绍了布局预览不显示ActionBar溢出选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里有一个小问题,其中ActionBar的溢出选项显示在模拟器中,而不显示在布局预览中.我目前正在使用Android Studio v 2.1.3.

I'm having a slight issue here where the overflow options for the ActionBar are showing up in the emulator but not the layout preview. I'm currently using Android Studio v 2.1.3.

还有其他人遇到过同样的问题吗?

Has anyone else come across the same issue?

布局预览

仿真器屏幕截图

推荐答案

在布局文件中,将tools:menu属性直接添加到Toolbar小部件中:

In your layout file, add the tools:menu attribute directly to the Toolbar widget:

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

根据文档:

工具:菜单

旨在用于:任何根<View>

此属性指定布局预览应显示在哪个菜单中 应用栏.该值可以是一个或多个菜单ID,中间用 逗号(不带@ menu/或任何此类ID前缀,不带.xml 扩展名).

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

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

However, I find that it only works if:

  1. 该属性直接添加到Toolbar小部件
  2. 该值包含@menu/前缀
  1. the attribute is added directly to the Toolbar widget
  2. the value includes the @menu/ prefix

这篇关于布局预览不显示ActionBar溢出选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆