Android Menu Item With Both Icon And Text Together When Showasaction Is Never
Hi, how can I make my menu items have icons as well when showAsAction is never ?
Solution 1:
Use android:actionLayout
in menu item tag to specify custom lyout (icon with text).
Menu item will look like:
<item
android:id="@+id/edit_menu"
android:actionLayout="@layout/custom_edit_row"
android:orderInCategory="100"
android:title="@string/edit"
app:showAsAction="always"></item>
Edit
custom_edit_row.xml
will be:
<?xml version="1.0" encoding="utf-8"?><RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:id="@+id/relativeLayout1"style="@android:style/Widget.ActionButton"android:layout_width="wrap_content"android:layout_height="wrap_content"android:clickable="true"><ImageViewandroid:id="@+id/imageViewEdit"android:layout_width="wrap_content"android:layout_height="wrap_content"android:src="@drawable/edit_ic" /><TextViewandroid:id="@+id/tvEdit"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Edit" />
Solution 2:
<menuxmlns: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=".YourActivityName"><itemandroid:id="@+id/action_settings"android:icon="@android:drawable/btn_dialog"android:title="@string/action_settings"app:showAsAction="always"><menu><itemandroid:id="@+id/profile"android:icon="@drawable/common_google_signin_btn_icon_light_disabled"android:title="PROFILE"app:showAsAction="always" /></menu></item>
Solution 3:
Use this menu file, it worked fine for me.
<menuxmlns:android="http://schemas.android.com/apk/res/android" ><itemandroid:id="@+id/action_m"android:showAsAction="never"android:title="menu"><menu><itemandroid:id="@+id/action_one"android:icon="@android:drawable/ic_popup_sync"android:showAsAction="always"android:title="Sync"/><itemandroid:id="@+id/action_two"android:icon="@android:drawable/ic_dialog_info"android:title="About"/></menu></item></menu>
Solution 4:
In createOptionsMenu, set the icon and text to MenuItem.
Elaborate the problem a little more.
Solution 5:
Just change root item of Harry Mad answer
<itemandroid:title="Ещё"app:showAsAction="always"android:icon="@drawable/ic_more_vert">
...
Post a Comment for "Android Menu Item With Both Icon And Text Together When Showasaction Is Never"