单击按钮时,我将显示包含语言列表的菜单。现在我希望图标显示在菜单中每个项目的标题右侧。我用谷歌搜索但没有找到合适的解决方案,请帮助我。
菜单语言.xml:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/nav_arabic"
android:title="Arabic" />
<item
android:id="@+id/nav_southAfrica"
android:icon="@drawable/ic_earphones"
android:title="Afrikaans"
/>
<item
android:id="@+id/nav_albania"
android:icon="@drawable/ic_earphones"
android:title="Albanian " />
<item
android:id="@+id/nav_armenian"
android:title="Armenian" />
<item
android:id="@+id/nav_azerbaijani"
android:icon="@drawable/ic_earphones"
android:title="Azerbaijani" />
<item
android:id="@+id/nav_bangla"
android:icon="@drawable/ic_earphones"
android:title="Bangla" />
<item
android:id="@+id/nav_basque"
android:icon="@drawable/ic_earphones"
android:title="Basque" />
<item
android:id="@+id/nav_belarusian"
android:title="Belarusian" />
语言.java:
public void showMenu(View v) {
PopupMenu popup = new PopupMenu(getActivity(), v);
Object menuHelper;
Class[] argTypes;
try {
Field fMenuHelper = PopupMenu.class.getDeclaredField("mPopup");
fMenuHelper.setAccessible(true);
menuHelper = fMenuHelper.get(popup);
argTypes = new Class[]{boolean.class};
menuHelper.getClass().getDeclaredMethod("setForceShowIcon", argTypes).invoke(menuHelper, true);
} catch (Exception e) {
}
MenuInflater inflater = popup.getMenuInflater();
inflater.inflate(R.menu.menu_language, popup.getMenu());
popup.setOnMenuItemClickListener(this);
到目前为止,该图标位于菜单的左侧,但我希望它位于标题的右侧。请帮忙,有什么线索吗?