简体   繁体   English

如何更改 CollapsibleToolbar 标题的颜色?

[英]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.

相关问题 如何更改 AlertDialog 标题的颜色及其下方线条的颜色 - How can I change the color of AlertDialog title and the color of the line under it 如何更改对话框的标题颜色? - how can I change dialog box's title color? 如何轻松更改我的应用程序标题文本颜色? - How can I painlessly change my app Title text color? Android:如何在不使用自定义布局的情况下更改 AlertDialog 标题文本颜色和背景颜色? - Android: How can I change AlertDialog Title Text Color and Background Color without using custom layout? 为什么PreferenceCategory的标题和复选框的颜色这么浅,我该如何更改? - Why PreferenceCategory's title & checkBox color is so light & how can I change it? 如何在暂停应用程序时更改操作栏的标题文本颜色? - How can I change the title text color of the action bar when the app is paused? 我们如何更改android中customactionbar的标题文本颜色? - how can we change the title text color of customactionbar in android? 如何更改 DatePickerDialog 的标题颜色? - How to change title color of DatePickerDialog? 如何在操作栏标题中更改颜色 - how to change color in actionbar title 如何更改微调器的标题 - How I can change the title of the spinner
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM