Android ActionBar上的自定义菜单项
我现在在使用菜单中的android:actionLayout时遇到问题 我用过这个,在我以前的一些项目中工作过,但现在我不知道发生了什么 我打字的时候Android ActionBar上的自定义菜单项,android,android-actionbar,android-menu,Android,Android Actionbar,Android Menu,我现在在使用菜单中的android:actionLayout时遇到问题 我用过这个,在我以前的一些项目中工作过,但现在我不知道发生了什么 我打字的时候 android:title="@string/menu_notifications" android:actionLayout="@layout/menu_notification" 我的应用程序中actionBar中的每个图标都变为文本 我试过很多东西,但都没用。我不知道发生了什么事 请给我一些建议/想法 编辑: menu_notificat
android:title="@string/menu_notifications"
android:actionLayout="@layout/menu_notification"
我的应用程序中actionBar中的每个图标都变为文本
我试过很多东西,但都没用。我不知道发生了什么事
请给我一些建议/想法
编辑:
menu_notification.xml
将菜单_notification.xml更改为
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="TEST"
android:textSize="20dp"
android:textColor="#F00"
/>
}您确定菜单通知是XML吗?您测试的操作系统版本是什么?您可以发布您的通知吗xml@MSS我用我的电脑做了编辑xml@deathember我在版本4.2.2上测试此功能,但不起作用,只显示相同的文本“通知”。
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="TEST"
android:textSize="20dp"
android:textColor="#F00"
/>
<item
android:id="@+id/log_out"
android:actionLayout="@layout/menu_notification"
android:icon="@drawable/power"
android:showAsAction="always"
/>
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);
TextView txtview=(TextView )menu.findItem(R.id.log_out).getActionView();
//do remaining stuff here