如何在BottomNavigationView中的所选项目上应用文本样式? 我可以更改颜色,但无法弄清楚如何更改所选菜单项上的字体样式(如字体系列或使其变为粗体/斜体)。有没有一种方法只能使用XML?
在上面的示例图片中,我只希望SEARCH使用不同的字体和粗体。 MESSAGE和DASHBOARD保持不变。
在活动xml中:
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="0dp"
android:layout_height="49dp"
android:background="?android:attr/windowBackground"
android:paddingBottom="5dp"
android:paddingTop="5dp"
app:itemIconTint="@color/bottom_nav_color"
app:itemTextColor="@color/bottom_nav_color"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/navigation"/>
res / menu / navigation.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/navigation_search"
android:icon="@drawable/ic_search"
android:title="SEARCH" />
<item
android:id="@+id/navigation_messages"
android:icon="@drawable/ic_question_answer"
android:title="MESSAGES" />
<item
android:id="@+id/navigation_dashboard"
android:icon="@drawable/ic_dashboard_black_24dp"
android:title="DASHBOARD" />
</menu>
res / color / bottom_nav_color.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:color="@color/colorPrimary" />
<item android:state_checked="false" android:color="#666666"/>
</selector>
答案 0 :(得分:1)
我想在这里值得一提的是,通过更改文本样式,您不会更改文本颜色。因此,仍然需要使用app:itemTextColor
<com.google.android.material.bottomnavigation.BottomNavigationView
...
app:itemIconTint="@color/bottom_nav_color_selector"
app:itemTextColor="@color/bottom_nav_color_selector"
app:itemTextAppearanceInactive="@style/BottomNavigationText"
app:itemTextAppearanceActive="@style/BottomNavigationText.Selected"
tools:menu="@menu/menu_bottom_navigation"
/>
颜色选择器
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/bottom_nav_selected" android:state_checked="true" />
<item android:color="@color/bottom_nav_normal" />
</selector>
样式
<style name="BottomNavigationText" parent="@android:style/TextAppearance"/>
<style name="BottomNavigationText.Selected">
<item name="android:textStyle">bold</item>
</style>
答案 1 :(得分:0)
在BottomNavigationView中有称为itemTextAppearanceActive和itemTextAppearanceInactive的属性。只需在res / values / styles.xml中创建样式:
library(tidyverse)
library(rvest)
year <- list(1979:2018)
new_list <- NULL
然后在BottomNavigationView中引用它:
for (i in year) {
new_list <- c(new_list, paste("https://www.hockey-reference.com/draft/NHL_",i,"_entry.html", sep = ""))
for (y in new_list) {
url <- as.character(y)
export <- url %>% read_html() %>% html_nodes("table") %>% .[[1]] %>% html_table()
# Write to csv file
write_csv(export, path = paste0("~/hockey_draft/csv/",i,".csv"))
}
}
反之亦然。