How can I change the NavigationView's item text size?
Since Android Support Library 22.2.1, Google has changed default textSize of items in NavigationView
from 16sp to 14sp, which suits Material Design guideline well. However, in some cases(for example, when you want to support Chinese language), it seems larger textSize is better. Solution is simple:
- add
app:theme="@style/yourStyle.Drawer"
to yourNavigationView
in your layout.xml - in styles.xml, add
android:textSize="16sp"
in styleyourStyle.Drawer
How can change textsize of menu item?
Instead of setting the theme for every element, set the theme to your Navigationview
. Like,
<style name="NavDrawerTextStyle">
<item name="android:textSize">50sp</item>
</style>
to Navigationview
<android.support.design.widget.NavigationView
...
android:theme="@style/NavDrawerTextStyle"
/>
Changing the item text size in navigation view
Create a style and apply it to NavigationView using app:theme
<style name="NavigationViewStyle">
<item name="android:textSize">20sp</item> <!-- menu item text size-->
<item name="android:listPreferredItemHeightSmall">40dp</item><!-- menu item height-->
</style>
And then as said, apply this style to NavigationView using app:theme
<android.support.design.widget.NavigationView
...
...
app:theme="@style/NavigationViewStyle"
...
...
</android.support.design.widget.NavigationView>
How to change the font and the size of a NavigationView menu item?
You can use a SpannableString
:
val item: MenuItem = nav.menu.findItem(R.id.nav_user)
val spannableString = SpannableString(item.title.toString())
spannableString.setSpan(RelativeSizeSpan(1.5f), 0, spannableString.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
spannableString.setSpan(TypefaceSpan("font_name"), 0, spannableString.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
item.title = spannableString
the RelativeSizeSpan
value 1.5f
is a relative and not absolute value for the text size, so adjust it as you wish.
font size of items inside navigation drawer not changing
You must apply this attribute:
android:theme="@style/DrawerTextStyle"
to the NavigationView
and not to the menu,
but first change dp
to sp
:
<style name="DrawerTextStyle" >
<item name="android:textColor">@color/colorPrimaryDark</item>
<item name="android:textSize">40sp</item>
<item name="android:textStyle">bold</item>
</style>
Custom TextSize of BottomNavigationView support android
Unfortunately this first version of BottomNavigationView came with a lot of limitations. And for now you can't change titles size just using the support design API. So to solve this limitation while google doesn't implement it, you can do:
In your dimen.xml you can put:
<dimen name="design_bottom_navigation_text_size" tools:override="true">30sp</dimen>
<dimen name="design_bottom_navigation_active_text_size" tools:override="true">30sp</dimen>
Doing this you are overriding the default value of dimen that the internal classes of BottomNavigationView use. So be carreful.
Adding font size to NavigationView item in android
Try like below
//put this in main Activity
private void setFontToMenuItem(MenuItem mi) {
Typeface font = Typeface.createFromAsset(getAssets(), "fonts/customfont.ttf");
SpannableString mNewTitle = new SpannableString(mi.getTitle());
mNewTitle.setSpan(new CustomTypefaceSpan("" , font), 0 , mNewTitle.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
mi.setTitle(mNewTitle);
}
Use like this
navigationView = (NavigationView) findViewById(R.id.navigation_view);
Menu m = navigationView.getMenu();
for (int i=0;i<m.size();i++) {
MenuItem item = m.getItem(i);
//for aapplying a font to subMenu ...
SubMenu subMenu = item.getSubMenu();
if (subMenu!=null && subMenu.size() >0 ) {
for (int j=0; j <subMenu.size();j++) {
MenuItem subMenuItem = subMenu.getItem(j);
setFontToMenuItem(subMenuItem);
}
}
//the method we have create in activity
setFontToMenuItem(item);
}
Related Topics
Android Studio - Error:Program Type Already Present
Is Fcm (Firebase Cloud Messaging) Token for One Device or for One Account
Is There an Android Based Google Glass Emulator
Provide the Caller Id for Incoming Call from My Own App
Getting a JSONexception: End of Input at Character 0
Error Building Android Library: Direct Local .Aar File Dependencies Are Not Supported
Email Verification Using Firebase 3.0 on Android
Particular Title(Fetched from API) Using Searchview
Android: Support Multiple Screens
How to Create a Release Android Library Package (Aar) in Android Studio (Not Debug)
Want to Load Desktop Version in My Webview Using Uastring
When Should I Recycle a Bitmap Using Lrucache
How to Set Up Gradle and Android Studio to Do Release Build
How to View Data Saved in Android Database(Sqlite)
Shaking/Wobble View Animation in Android