[英]How can I change the color of a CollapsibleToolbar title?
So, I'm struggling for a few days meddling with lots of different attributes, but still couldn't figure out how to change the text color of a Collapsing toolbar's title.因此,我在处理许多不同的属性方面苦苦挣扎了几天,但仍然无法弄清楚如何更改折叠工具栏标题的文本颜色。 Any takes on this?
对此有什么看法吗? Here's a very simple layout I've been experimenting with.
这是我一直在试验的一个非常简单的布局。 The
app:titleTextColor="@color/colorPrimary"
produces no effect. app:titleTextColor="@color/colorPrimary"
没有效果。
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/appBarLayout"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|snap|exitUntilCollapsed"
app:contentScrim="@color/colorPrimary"
app:expandedTitleGravity="center|top"
app:title="@string/app_name"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="250dp"
android:src="@drawable/zebra"
android:scaleType="centerCrop"
android:contentDescription="@string/zebras"
/>
<androidx.appcompat.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="@style/ThemeOverlay.AppCompat.Dark"
app:titleTextColor="@color/colorPrimary"
/>
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Add styles in styles.xml在styles.xml中添加样式
<style name="CollapsedAppBarText" parent="@android:style/TextAppearance.Medium">
<item name="android:textSize">16sp</item>
<item name="android:textColor">@color/blue</item>
<item name="android:textStyle">normal</item>
</style>
then Activity/ fragment use like this然后活动/片段像这样使用
collapsingToolbar = findViewById<View>(R.id.collapsing_toolbar) as CollapsingToolbarLayout
collapsingToolbar?.setCollapsedTitleTextAppearance(R.style.CollapsedAppBarText)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.