I know this question was asked many times and I used many solutions but it doesn't work for me . I want to change the direction of my Menu
to rtl
using a Popup
but It doesn't work .
my menu
<menu xmlns:android="http://schemas.android.com/apk/res/android"
android:layoutDirection="rtl">
<item
android:id="@+id/more"
android:title="@string/menue" />
<item
android:id="@+id/rate"
android:title="@string/rate"/>
<item
android:id="@+id/share"
android:title="@string/share" />
my popup
imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
PopupMenu popup = new PopupMenu(MainActivity.this, imageButton );
popup.getMenuInflater().inflate(R.menu.app_menue, popup.getMenu());
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
switch (menuItem.getItemId()) {
case R.id.more:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(res.getString(R.string.moreApps)));
startActivity(intent);
break;
case R.id.rate:
Intent intent1 = new Intent(Intent.ACTION_VIEW);
intent1.setData(Uri.parse(res.getString(R.string.rateApp)));
startActivity(intent1);
break;
case R.id.share:
Intent myIntent = new Intent(Intent.ACTION_SEND);
myIntent.setType("text/plain");
String shareBody = "Share our app";
myIntent.putExtra(Intent.EXTRA_SUBJECT, shareBody);
myIntent.putExtra(Intent.EXTRA_TEXT, res.getString(R.string.shareApp));
startActivity(Intent.createChooser(myIntent, "Share using"));
break;
}
return true;
}
});
popup.show();
}
});
And in my Manifest
android:supportsRtl="true"
I found a solution .
Making my own style like this
<style name="menuStyle">
<item name="android:layoutDirection">rtl</item>
</style>
Then add this code
Context myContext = new ContextThemeWrapper(MainActivity.this,R.style.menuStyle);
PopupMenu popupMenu = new PopupMenu(myContext , myView);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With