I have a popup menu that works. The user would press an image and a popup menu appears with 5 items. The problem is that I don't seem to be able to change the size of the text of the popup. The Java that calls the popup is as follows:
public void TheCompanyMenu(View v) {
PopupMenu mypopupmenu = new PopupMenu(this, v);
mypopupmenu.setOnMenuItemClickListener(this);
MenuInflater inflater = mypopupmenu.getMenuInflater();
inflater.inflate(R.menu.popup, mypopupmenu.getMenu());
mypopupmenu.show();
}
@Override
public boolean onMenuItemClick(MenuItem arg0) {
switch (arg0.getItemId()) {
case R.id.option1:
Intent intent1 = new Intent(this, MainActivity.class);
startActivity(intent1);
return true;
case R.id.option2:
Intent intent2 = new Intent(this, Item2.class);
startActivity(intent2);
return true;
case R.id.option3:
Intent intent3 = new Intent(this, Item3.class);
startActivity(intent3);
return true;
case R.id.option4:
Intent intent4 = new Intent(this, Item4.class);
startActivity(intent4);
return true;
case R.id.option5:
Intent intent5 = new Intent(this, Item5.class);
startActivity(intent5);
return true;
default:
return super.onContextItemSelected(arg0);
}
}
The Menu xml called popup is as follows:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/option1"
style="@style/PopupItemStyle"
android:textSize="12sp"
android:text="@string/HomeMenu"
android:title="@string/HomeMenu" />
<item android:id="@+id/option2"
style="@style/PopupItemStyle"
android:textSize="12sp"
android:text="@string/option2"
android:title="@string/option2menu" />
<item android:id="@+id/option3"
style="@style/PopupItemStyle"
android:textSize="12sp"
android:text="@string/option3"
android:title="@string/option3menu" />
<item android:id="@+id/option4"
style="@style/PopupItemStyle"
android:textSize="12sp"
android:text="@string/option4"
android:title="@string/option4menu" />
<item android:id="@+id/option5"
style="@style/PopupItemStyle"
android:textSize="12sp"
android:text="@string/option5"
android:title="@string/option5Menu" />
</menu>
I have tried changing the android:textSize to be dp but it has no effect.
The code in the style xml is:
<style name="PopupItemStyle">
<item name="android:background">#FFA0A0A0</item>
<item name="android:gravity">center</item>
<item name="android:padding">10dp</item>
<item name="android:textStyle">bold</item>
<item name="android:textSize">12sp</item>
</style>
As I am fairly new to Java, I am keen to keep the java bit as it is (i.e. using popupmenu) as it is working (sort of), but need to change the text size. Thanks a lot!