1

I have looked around many times already at different posts and none of them have solved this problem for me. My XML defined menu item always show up in the the overflow, and it show up twice. Here is the XML file:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<item
    android:id="@+id/add_Playlist"
    android:icon="@android:drawable/ic_menu_add"
    app:showAsAction="ifRoom|withText"
    android:title="@string/addPlaylist" />

</menu>

I'm inflating the menu on top of my toolbar in the activity file:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    setActionBar((android.widget.Toolbar) findViewById(R.id.toolbar));

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu items for use in the action bar
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu_main, menu);
    return super.onCreateOptionsMenu(menu);
}

And yet the menu items show up in the overflow. In Android Studio's render view the menu looks correct.

If you want me to attach a snapshot I will. I'm running the app on an emulator with API 23 (For now). I don't know if I should include any other files but tell me if you want them. Thanks in advance!

[EDIT] Here is a screenshot of the toolbar: https://gyazo.com/2743b74a8aee07035b8398f1b41002c4

Here is my styles.xml:

<resources
xmlns="http://schemas.android.com/apk/res-auto">
<color name="card_title_text">#111111</color>
<color name="card_desc_text">#aaaaaa</color>
<color name="action_bar_text">#ffffff</color>

<!-- Base application theme. -->
<style name="AppTheme" parent="@style/Theme.AppCompat.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="actionMenuTextColor">@color/action_bar_text</item>
    <item name="android:navigationBarColor">@color/black</item>
    <item name="android:colorForeground">@color/foreground_material_light</item>
    <item name="android:colorBackground">@color/background_material_light</item>
    <item name="android:statusBarColor">@color/statusBarColor</item>
    <item name="android:windowBackground">@color/windowBackground</item>
</style>
<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="actionMenuTextColor">@color/action_bar_text</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />


</resources>

I also tried setting app:showAsAction="always" but it didn't work. No visible change.

3
  • Please attach snapshot. Commented Oct 23, 2015 at 18:55
  • Were you able to find a solution for this? Commented Mar 3, 2016 at 19:43
  • no I wasn't able to. Commented Mar 30, 2016 at 18:32

1 Answer 1

2

I'm not sure I understand fully - do you mean you want to see the icons in the toolbar instead of the words in your @string/addPlaylist

If so, you need to change the following line in your menu item:

app:showAsAction="always"
Sign up to request clarification or add additional context in comments.

4 Comments

Yes, I want to see the icons instead of text. However it shows up only as text in the overflow menu and it shows up twice.
Are you using a theme with a toolbar or a noToolbar theme? If you are defining a toolbar in xml and a toolBar theme at the same time, you might see a duplication. Can you post a screenshot of what your toolbar looks like?
also to inflate the toolBar, you normally use the method toolBar.inflateMenu(int resId)
I've added a screenshot as you asked. What do you mean by using toolbar.inflateMenu()?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.