Menu item not shown as action android.support.v7.widget.Toolbar
The Actionbar menu does not show up as an action even though I only have one manu item. !! this is my menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity" >
<item
android:id="@+id/action_search"
android:title="@string/action_search"
android:icon="@drawable/ic_search"
android:showAsAction="ifRoom" />
</menu>
and i am using support bar: android.support.v7.widget.Toolbar code:
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="@color/colorPrimary"
local:theme = "@style/ThemeOverlay.AppCompat.Dark.ActionBar"
local:popupTheme="@style/ThemeOverlay.AppCompat.Light"
/>
And I am setting the action bar with the following lines:
Toolbar mToolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
Then what is wrong with my code? I'm using the shoAsAction = "ifRoom" attribute, but why isn't it showing up as an action in the action bar ..? can anyone help me?
+3
source to share
1 answer
use android:showAsAction="always"
insteadandroid:showAsAction="ifRoom"
for example
<item
android:id="@+id/action_search"
android:title="@string/action_search"
android:icon="@drawable/ic_search"
android:showAsAction="always" />
EDIT
FOR COMPACT LIBRARY APP
use `app:showAsAction="always"` instead of `android:showAsAction="ifRoom"`
+7
source to share