Note that there are some explanatory texts on larger screens.

plurals
  1. POchanging text size on popupmenu android
    text
    copied!<p>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:</p> <pre><code> 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); } } </code></pre> <p>The Menu xml called popup is as follows:</p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;menu xmlns:android="http://schemas.android.com/apk/res/android"&gt; &lt;item android:id="@+id/option1" style="@style/PopupItemStyle" android:textSize="12sp" android:text="@string/HomeMenu" android:title="@string/HomeMenu" /&gt; &lt;item android:id="@+id/option2" style="@style/PopupItemStyle" android:textSize="12sp" android:text="@string/option2" android:title="@string/option2menu" /&gt; &lt;item android:id="@+id/option3" style="@style/PopupItemStyle" android:textSize="12sp" android:text="@string/option3" android:title="@string/option3menu" /&gt; &lt;item android:id="@+id/option4" style="@style/PopupItemStyle" android:textSize="12sp" android:text="@string/option4" android:title="@string/option4menu" /&gt; &lt;item android:id="@+id/option5" style="@style/PopupItemStyle" android:textSize="12sp" android:text="@string/option5" android:title="@string/option5Menu" /&gt; &lt;/menu&gt; </code></pre> <p>I have tried changing the android:textSize to be dp but it has no effect.</p> <p>The code in the style xml is:</p> <pre><code> &lt;style name="PopupItemStyle"&gt; &lt;item name="android:background"&gt;#FFA0A0A0&lt;/item&gt; &lt;item name="android:gravity"&gt;center&lt;/item&gt; &lt;item name="android:padding"&gt;10dp&lt;/item&gt; &lt;item name="android:textStyle"&gt;bold&lt;/item&gt; &lt;item name="android:textSize"&gt;12sp&lt;/item&gt; &lt;/style&gt; </code></pre> <p>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!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload