在menu.xml中,我有两个项目。它在LTR模式下正确显示..但在RTL中,它无法正确显示。缺少一个项目。我附上了截图和代码。我需要更改标题名称的颜色。
我在清单文件中添加了supportRTL =“true”
菜单。 XML
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
>
<item android:id="@+id/action_settings"
android:title="@string/action_settings"
app:showAsAction="never" />
<item
android:id="@+id/notification"
android:title="Notification"
app:actionLayout="@layout/badge_counter"
app:showAsAction="always"/>
</menu>
码:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu, menu);
// Create a condition (hide it if the count == 0)
if (mNotificationCounter > -1) {
BadgeCounter.update(this,
menu.findItem(R.id.notification),
R.drawable.noti,
BadgeCounter.BadgeColor.BLUE,
mNotificationCounter);
} else {
BadgeCounter.hide(menu.findItem(R.id.notification));
}
this.menu = menu;
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
this.menuItem = item;
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
} else if (id == R.id.notification) {
// If you want to update
// mNotificationCounter--;
}
return super.onOptionsItemSelected(item);
}
请注意单独的通知图标丢失。
尝试在..中定义菜单标签
android:layoutDirection="rtl"
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layoutDirection="rtl"
>