Try to add this code in dimens.xml
file
<dimen name="design_bottom_navigation_text_size" tools:override="true">10sp</dimen>
<dimen name="design_bottom_navigation_active_text_size" tools:override="true">10sp</dimen>
You can set the active and inactive textAppearance for a BottomNavigationView via styles:
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/BottomNavigationView"/>
Put below styles in styles.xml
file
<style name="BottomNavigationView">
<item name="itemTextAppearanceActive">@style/TextAppearance.BottomNavigationView.Active</item>
<item name="itemTextAppearanceInactive">@style/TextAppearance.BottomNavigationView.Inactive</item>
</style>
<!-- blank styles for better code readability-->
<style name="TextAppearance"/>
<style name="TextAppearance.BottomNavigationView"/>
<!-- inactive tab icon style -->
<style name="TextAppearance.BottomNavigationView.Inactive">
<item name="android:textSize">12sp</item>
</style>
<!-- active tab icon style -->
<style name="TextAppearance.BottomNavigationView.Active">
<item name="android:textSize">12sp</item>
</style>
With TextAppearance you can control more than just textSize
, but also properties such as fontFamily
, etc.
You have to do 2 simple things if your using support library ' 28.0.0-alpha1 ' or higher -
Add below two lines in your dimen.xml file
<dimen name="design_bottom_navigation_text_size" tools:override="true">15sp</dimen>
<dimen name="design_bottom_navigation_active_text_size" tools:override="true">15sp</dimen>
And in view -
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:foreground="?attr/selectableItemBackground"
app:itemIconTint="@color/colorAccent"
app:itemTextColor="@color/colorAccent"
android:elevation="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:labelVisibilityMode="labeled"
app:menu="@menu/navigation" />
Put app:labelVisibilityMode="labeled"
That's all enjoy :-)
All control UI BottomNavigationView, below. I used dependence com.google.android.material:material for BottomNavigationView.
private void editBottomNavigationViewItems(BottomNavigationView bottomNavigationView) {
for (int i = 0; i < bottomNavigationView.getChildCount(); i++) {
try {
View item = bottomNavigationView.getChildAt( i );
if (item instanceof BottomNavigationMenuView) {
BottomNavigationMenuView menu = (BottomNavigationMenuView) item;
for (int j = 0; j < menu.getChildCount(); j++) {
try {
View menuItem = menu.getChildAt( j );
// not chosen item menu GO
View _small = menuItem.findViewById(com.google.android.material.R.id.smallLabel);//dependence com.google.android.material:material
//View _small = menuItem.findViewById(android.support.design.R.id.smallLabel);// dependence android.support.design
if ( _small instanceof TextView ) {
//_small.setPadding(0, 0, 0, 0);// remove all padding
TextView _tv = (TextView)_small;
_tv.setTextSize( 12 );// set size text
}// not chosen item menu END
//this chosen item menu GO
View _large = menuItem.findViewById(com.google.android.material.R.id.largeLabel);//dependence com.google.android.material:material
//View _large = menuItem.findViewById(android.support.design.R.id.largeLabel);//dependence android.support.design.R.id.largeLabel
if ( _large instanceof TextView ) {
_large.setPadding(0,0,0,0);// remove all padding
TextView _tv = (TextView)_large;
_tv.setTextSize( 12 );// set size text
}// this chosen item menu END
} catch ( NullPointerException npei ) {
Log.e("TAG", "get:BottomNavigationMenuView: " + npei.getMessage() );
}
}
}
} catch ( NullPointerException npe ) {
Log.e("TAG", "get:BottomNavigationView: " + npe.getMessage() );
}
}
}
Use this method in onCreate() and before bottom_navigation_menu.setOnNavigationItemSelectedListener:-
public void removePaddingFromBottomNavigationItem() {
BottomNavigationMenuView menuView = (BottomNavigationMenuView) bottom_navigation_menu.getChildAt(0);
for (int i = 0; i < menuView.getChildCount(); i++) {
BottomNavigationItemView item = (BottomNavigationItemView) menuView.getChildAt(i);
View activeLabel = item.findViewById(R.id.largeLabel);
if (activeLabel instanceof TextView) {
activeLabel.setPadding(0, 0, 0, 0);
}
}
}
And use this code in styles.xml:-
<style name="TextAppearance.BottomNavigationView.Inactive">
<item name="android:textSize">@dimen/_10ssp</item>
</style>
<style name="TextAppearance.BottomNavigationView.Active">
<item name="android:textSize">@dimen/_10ssp</item>
</style>
Try with below line in dimen.xml
<dimen name="design_bottom_navigation_text_size" tools:override="true">8sp</dimen>
<dimen name="design_bottom_navigation_active_text_size" tools:override="true">8sp</dimen>
<dimen name="design_bottom_navigation_icon_size">15dp</dimen>
<dimen name="design_bottom_navigation_height">45dp</dimen>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.