android:theme toolbar,android - AppCompat Toolbar: set toolbar theme from upper theme - Stack Overfl...

该博客介绍了如何在Android应用中一次性设定全局主题,并详细说明了如何将样式应用于所有活动和Fragment中的ToolBar,包括颜色配置、ToolBar的定制以及如何改变导航和溢出按钮的颜色。通过设置主题和在布局文件中引用,可以实现一致的视觉效果。
摘要由CSDN通过智能技术生成

If I understand the question correctly, you want to set your app's theme once and apply all the styling to all the Toolbars in every activity/fragment.

If so, I would recommend this approach:

@color/MyColorPrimaryText

@color/MyColorWindowBackground

@color/MyColorPrimary

@color/MyColorPrimaryDark

@color/MyColorAccent

@color/MyColorControlNormal

@color/MyColorControlHighlight

@style/MyToolbar

true

@color/MyColorPrimaryDark

match_parent

wrap_content

@dimen/MyToolbarMinHeight

center_vertical

@color/MyColorPrimary

10dp

@style/MyToolbarTheme

@color/MyColorPrimaryText

@color/MyToolbarColorControlNormal

@color/MyToolbarColorControlHighlight

Then in your manifest:

android:name=".MyApp"

android:theme="@style/MyTheme">

Then in your activity layout files, include the toolbar with:

style="?attr/toolbarStyle"

So myActivity1.xml layout file would look like this:

xmlns:tools="http://schemas.android.com/tools"

android:orientation="vertical"

android:layout_width="match_parent"

android:layout_height="match_parent">

android:id="@+id/appBar"

android:layout_width="match_parent"

android:layout_height="wrap_content"

style="?attr/toolbarStyle" />

And notice that to change the navigation back button color or the overflow button colors, you can set:

@color/MyColorControlNormal

@color/MyColorControlHighlight

And:

@color/MyColorPrimaryText

Can be used to update the actionbar text color but you'd define it in the Toolbar theme.

Hope this helps.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值