Skip to content Skip to sidebar Skip to footer

Changing Text Size Of Menu Item In Android

I am using simple menu items in action bar by using following code in main activity: package com.kaasib.ftpclient; import android.app.Activity; import android.os.Bundle; impor

Solution 1:

Ok, so this is my solution, you can actually use the SpannableString for fetching the text and then changing the font via RelativeSizeSpan (if you want text size relative to the default one) or via AbsoluteSizeSpan (if you want to manually input the text size):

publicbooleanonCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    MenuInflaterawesome= getMenuInflater();
    awesome.inflate(R.menu.menu_main, menu);
    for(inti=0; i < menu.size(); i++) {
        MenuItemitem= menu.getItem(i);
    SpannableStringspanString=newSpannableString(menu.getItem(i).getTitle().toString());
        intend= spanString.length();
    spanString.setSpan(newRelativeSizeSpan(1.5f), 0, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    item.setTitle(spanString);
}
    returntrue;
}

This example increases the size of menu item texts by 50%.

Solution 2:

add into style xml file like this bottom code line your custom font size,,

after this

<stylename="menu_text_style"parent="@android:style/TextAppearance.DeviceDefault.Widget.ActionBar.Menu"><itemname="android:textSize">16sp</item><itemname="android:textColor">@color/tab_default_color</item><itemname="android:textAllCaps">false</item></style>

after have to "menu_text_style" add to your NavigationView

        app:itemTextAppearance="@style/menu_text_style"

Solution 3:

Add the "android:actionMenuTextAppearance" item for your activities in your styles.xml :

<stylename="AppThemeActivity"parent="Theme.AppCompat.Light"><itemname="android:actionMenuTextAppearance">@style/yourstyle</item>
    ...
</style>

Apply this style to your activity in your Manifest :

<activityandroid:theme="@style/AppThemeActivity".../>

Solution 4:

So it's been a long time since this was asked but I like this solution as steven smiths answer changes every view:

Add this line to NavigationView:

app:itemTextAppearance="@style/MenuItems"

And this to the styles :

<stylename="MenuItems"parent="AppTheme"><itemname="android:textSize">18sp</item><itemname="android:fontFamily">sans-serif-light</item></style>

Solution 5:

Works well, on old API also:

In your style.xml:

<stylename="AppTheme"parent="Theme.AppCompat.Light"><itemname="actionMenuTextAppearance">@style/ActionMenuTextAppearance</item><itemname="android:actionMenuTextAppearance">@style/ActionMenuTextAppearance</item></style><stylename="ActionMenuTextAppearance"parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Menu"><itemname="android:textSize">16sp</item><itemname="android:textColor">#1a1a1a</item></style>

In your manifest:

<activityandroid:name=".MainActivity"android:theme="@style/AppTheme"
        />

Post a Comment for "Changing Text Size Of Menu Item In Android"