Android修改Toolbar标题和菜单项字体大小和颜色

修改Toolbar标题字体大小

首先我们要写一个style:

<!-- 设置Toolbar标题字体的大小 -->
<style name="Toolbar.TitleText" parent="TextAppearance.Widget.AppCompat.Toolbar.Title">
	<item name="android:textSize">18sp</item>
</style>

然后在布局xml中使用:

<android.support.v7.widget.Toolbar
            xxxxxxxxxxxxxxxxxxx
            app:titleTextAppearance="@style/Toolbar.TitleText" />

修改菜单项字体大小和颜色

我在StackOverFlow上找到一个回答,可以参考一下:
Change Toolbar Menu Item color (non-hidden action)

首先我们要写一个style:

<!-- 设置Toolbar菜单文字的大小  -->
<style name="ToolbarTheme" parent="AppTheme.AppBarOverlay">
	<item name="actionMenuTextColor">@color/edit_green</item> <!--颜色-->
	<item name="android:textSize">@dimen/toolbar_action_menu_text</item> <!--字体大小-->
</style>

然后在toolbar布局xml中使用:

<android.support.v7.widget.Toolbar
            xxxxxxxxxxx
            app:theme="@style/ToolbarTheme"/>

这里对于改变字体大小没有什么好说的,但是改颜色有两个坑需要注意一下:
①上边style中item actionMenuTextColor前边是不能加android:的,加上之后就不行了!
②另外style中的父style也比较重要,一般写AppTheme.AppBarOverlay就可以了,写其他的要么就是颜色改变不了,要么就是整个toolbar深浅主题变了,导致toolbar中的标题也变了颜色,当然是在你没有设置标题颜色的前提下。因为Android默认会根据你主题的深浅,来设置默认的标题颜色,深主题就会设置一个浅色标题,浅主题就会设置一个深色标题。

经过测试,在5.0及以上,还有4.0的机子上均可正常改变颜色。
至于网上有些说要在style-v21中也写,而且要加上android:,完全没有必要!

TabLayout改变TabText的字体大小

这个跟改变Toolbar标题字体大小类似,也在这提一下。
首先写一个style:

<style name="TabText" parent="TextAppearance.Design.Tab">
	<item name="android:textSize">@dimen/tab_indicator_text</item>
</style>

然后在布局中使用:

<android.support.design.widget.TabLayout
            android:id="@+id/tablayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabGravity="fill"
            app:tabIndicatorColor="@color/tab_select_color"
            app:tabIndicatorHeight="@dimen/tab_indicator_height"
            app:tabMode="fixed"
            app:tabSelectedTextColor="@color/white"
            app:tabTextAppearance="@style/TabText"  //改变大小
            app:tabTextColor="@color/white" />
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值