使用您想要的视图创建布局文件,然后像这样使用它 –
android:id="@+id/menu_refresh"
android:title="@string/refresh"
yourapp:showAsAction="never"
android:actionLayout="@layout/my_custom_layout"/>
要编辑文本视图 –
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
//Get a reference to your item by id
MenuItem item = menu.findItem(R.id.menu_refresh);
//Here,you get access to the view of your item,in this case,the layout of the item has a RelativeLayout as root view but you can change it to whatever you use
RelativeLayout rootView = (RelativeLayout)item.getActionView();
//Then you access to your control by finding it in the rootView
TextView textview1 = (TextView) rootView.findViewById(R.id.text1);
//And from here you can do whatever you want with your text view
return true;
}