答案 0 :(得分:13)
尝试在dimens.xml
文件
<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>
答案 1 :(得分:12)
您可以通过样式为BottomNavigationView设置有效和无效文本外观:
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/BottomNavigationView"/>
在styles.xml
文件中放置以下样式
<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>
使用TextAppearance,您不仅可以控制textSize
,而且还可以控制fontFamily
等属性。
答案 2 :(得分:0)
如果使用支持库' 28.0.0-alpha1 '或更高版本-
,您必须做2件简单的事情在dimen.xml文件的两行下面添加
<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>
在视野中-
<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" />
放入app:labelVisibilityMode="labeled"
非常享受:-)
答案 3 :(得分:0)
下面的所有控件UI BottomNavigationView。 我将com.google.android.material:material依赖项用于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() );
}
}
}
答案 4 :(得分:0)
在onCreate()中和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);
}
}
}
并在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>
答案 5 :(得分:0)
尝试使用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>