2

I'm using the normal "options menu". When I change the Native size of my device from suppose "small" to "large" , my "options menu" also get changed with it.

I want some way in which i can keep the font size of my "options menu"static throughout the application .Regardless of my native size setting.

I've tried links like:

How to set a font for the Options menu?

but this way i have to insert every item. Is there some efficient way available??

Community
  • 1
  • 1
Nishant Virmani
  • 215
  • 1
  • 2
  • 10

2 Answers2

4

you can use onConfigurationChanged in Application class and set the old configuration again.

public class MyApp extends Application {

 Configuration config;
private float mDefaultFont=1.15f;

@Override
public void onCreate() {
    super.onCreate();
    config = getResources().getConfiguration();
    config.fontScale=mDefaultFont;
    DisplayMetrics dm = getResources().getDisplayMetrics();
    getResources().updateConfiguration(config, dm);
  }
@Override
 public void onConfigurationChanged(Configuration newConfig) {
  super.onConfigurationChanged(config);
  config.fontScale = mDefaultFont;
  DisplayMetrics dm = getResources().getDisplayMetrics();
  getResources().updateConfiguration(config, dm);
  }
}
Meher
  • 2,545
  • 3
  • 26
  • 53
1

When you use sp units in textSize attributes, system respects native size setting. You may use dp units to ignore this behavior, nevertheless it is not recommended.

For options menu you can try to override menu style (itemTextAppearance available since api 11):

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="android:itemTextAppearance">@style/PopupMenuStyle</item>
    </style>

    <style name="PopupMenuStyle">
        <item name="android:textSize">12dp</item>
    </style>


</resources>
vokilam
  • 10,153
  • 3
  • 45
  • 56