Clement
Clement

Reputation: 4811

Layout preview not showing ActionBar overflow options

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?

Layout Preview

enter image description here

Emulator Screenshot

enter image description here

Upvotes: 3

Views: 295

Answers (2)

user11566289
user11566289

Reputation:

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"/>

According to the 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).

However, I find that it only works if:

  1. the attribute is added directly to the Toolbar widget
  2. the value includes the @menu/ prefix

Upvotes: 1

yital9
yital9

Reputation: 6712

Try to add a tools:menu to your root view in the layout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:menu="menu1,menu2" />

more info here: http://tools.android.com/tech-docs/tools-attributes

Upvotes: 0

Related Questions