Hi, how can I make my menu items have icons as well when showAsAction is never ?
嗨,当showAsAction不存在时,我怎么能让我的菜单项也有图标呢?
5 个解决方案
#1
1
Use this menu file, it worked fine for me.
使用这个菜单文件,它对我很好。
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/action_m"
android:showAsAction="never"
android:title="menu">
<menu>
<item
android:id="@+id/action_one"
android:icon="@android:drawable/ic_popup_sync"
android:showAsAction="always"
android:title="Sync"/>
<item
android:id="@+id/action_two"
android:icon="@android:drawable/ic_dialog_info"
android:title="About"/>
</menu>
</item>
</menu>
#2
0
In createOptionsMenu, set the icon and text to MenuItem.
在createOptionsMenu中,将图标和文本设置为MenuItem。
Elaborate the problem a little more.
再详细说明一下这个问题。
#3
0
Just change root item of Harry Mad answer
只改变哈利疯狂回答的根项
<item
android:title="Ещё"
app:showAsAction="always"
android:icon="@drawable/ic_more_vert">
...
#4
0
Use android:actionLayout
in menu item tag to specify custom lyout (icon with text). Menu item will look like:
在菜单项标签中使用android:actionLayout来指定自定义布局(带有文本的图标)。菜单项如下:
<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"?>
<RelativeLayout xmlns: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">
<ImageView
android:id="@+id/imageViewEdit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/edit_ic" />
<TextView
android:id="@+id/tvEdit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Edit" />
#5
0
<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=".YourActivityName">
<item
android:id="@+id/action_settings"
android:icon="@android:drawable/btn_dialog"
android:title="@string/action_settings"
app:showAsAction="always">
<menu>
<item
android:id="@+id/profile"
android:icon="@drawable/common_google_signin_btn_icon_light_disabled"
android:title="PROFILE"
app:showAsAction="always" />
</menu>
</item>
#1
1
Use this menu file, it worked fine for me.
使用这个菜单文件,它对我很好。
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/action_m"
android:showAsAction="never"
android:title="menu">
<menu>
<item
android:id="@+id/action_one"
android:icon="@android:drawable/ic_popup_sync"
android:showAsAction="always"
android:title="Sync"/>
<item
android:id="@+id/action_two"
android:icon="@android:drawable/ic_dialog_info"
android:title="About"/>
</menu>
</item>
</menu>
#2
0
In createOptionsMenu, set the icon and text to MenuItem.
在createOptionsMenu中,将图标和文本设置为MenuItem。
Elaborate the problem a little more.
再详细说明一下这个问题。
#3
0
Just change root item of Harry Mad answer
只改变哈利疯狂回答的根项
<item
android:title="Ещё"
app:showAsAction="always"
android:icon="@drawable/ic_more_vert">
...
#4
0
Use android:actionLayout
in menu item tag to specify custom lyout (icon with text). Menu item will look like:
在菜单项标签中使用android:actionLayout来指定自定义布局(带有文本的图标)。菜单项如下:
<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"?>
<RelativeLayout xmlns: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">
<ImageView
android:id="@+id/imageViewEdit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/edit_ic" />
<TextView
android:id="@+id/tvEdit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Edit" />
#5
0
<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=".YourActivityName">
<item
android:id="@+id/action_settings"
android:icon="@android:drawable/btn_dialog"
android:title="@string/action_settings"
app:showAsAction="always">
<menu>
<item
android:id="@+id/profile"
android:icon="@drawable/common_google_signin_btn_icon_light_disabled"
android:title="PROFILE"
app:showAsAction="always" />
</menu>
</item>