当 showAsAction 永远不会时,带有图标和文本的 Android 菜单项 [英] Android menu item with both icon and text together when showAsAction is never
本文介绍了当 showAsAction 永远不会时,带有图标和文本的 Android 菜单项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当 showAsAction 从来没有时,我怎样才能让我的菜单项也有图标?
Hi, how can I make my menu items have icons as well when showAsAction is never ?
推荐答案
在菜单项标签中使用 android:actionLayout
来指定自定义布局(带有文本的图标).菜单项将如下所示:
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>
编辑
custom_edit_row.xml
将是:
<?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" />
这篇关于当 showAsAction 永远不会时,带有图标和文本的 Android 菜单项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文