
这是我的工具栏xml
<?xml version="1.0" enCoding="utf-8"?><androID.support.v7.Widget.Toolbar xmlns:androID="http://schemas.androID.com/apk/res/androID" xmlns:app="http://schemas.androID.com/apk/res-auto" androID:ID="@+ID/toolbar" androID:layout_wIDth="match_parent" app:contentInsetEnd="0dp" app:contentInsetStart="0dp" androID:layout_height="@dimen/toolbar_height" app:theme="@style/themeOverlay.AppCompat.Dark.Actionbar" app:popuptheme="@style/themeOverlay.AppCompat.light" androID:background="@color/primary_color"></androID.support.v7.Widget.Toolbar>解决方法:
您可以通过编程或样式执行此 *** 作:
Toolbar toolbar; // your toolbartoolbar.setBackgroundcolor(newcolor); // i don't tested this method. Write if it's not workingtoolbar.setTitleTextcolor(Titlecolor); // if toolbar is white set Title to black, if toolbar is black set Title to white或者你可以用风格来做:
添加attrs.xml:
<?xml version="1.0" enCoding="utf-8"?><resources> <attr name="toolbarStyle" format="reference"/></resources>现在更改toolbar.xml:
<?xml version="1.0" enCoding="utf-8"?><androID.support.v7.Widget.Toolbar xmlns:androID="http://schemas.androID.com/apk/res/androID" xmlns:app="http://schemas.androID.com/apk/res-auto" androID:ID="@+ID/toolbar" androID:layout_wIDth="match_parent" app:contentInsetEnd="0dp" app:contentInsetStart="0dp" androID:layout_height="@dimen/toolbar_height" app:theme="?attr/toolbarStyle" app:popuptheme="@style/themeOverlay.AppCompat.light" androID:background="@color/primary_color"></androID.support.v7.Widget.Toolbar>在styles.xml中(如果你没有这个创建它):
<?xml version="1.0" enCoding="utf-8"?><resources> <style name="MyStyle.Dark" parent="AppCompat.theme"> <item name="toolbarStyle">@style/themeOverlay.AppCompat.Dark.Actionbar</item> </style> <style name="MyStyle.light" parent="AppCompat.theme.light"> <item name="toolbarStyle">@style/themeOverlay.AppCompat.light.Actionbar</item> </style></resources>如果选择第二种方法(带样式),则必须重新启动活动并在super.onCreate()之前使用settheme方法
我希望我帮助过你.
总结以上是内存溢出为你收集整理的android – 如何以编程方式更改AppCompat v21工具栏主题?全部内容,希望文章能够帮你解决android – 如何以编程方式更改AppCompat v21工具栏主题?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)