Skip to content

Commit 5c14772

Browse files
dsn5ftpekingme
authored andcommitted
[CollapsingToolbarLayout] Added support for expanded and collapsed title text color attributes
PiperOrigin-RevId: 375103699
1 parent 2a23ef4 commit 5c14772

File tree

4 files changed

+36
-16
lines changed

4 files changed

+36
-16
lines changed

docs/components/TopAppBar.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -430,22 +430,22 @@ Element | Attribute | Related m
430430

431431
#### Title attributes
432432

433-
Element | Attribute | Related method(s) | Default value
434-
-------------------------------------------------------- | ----------------------------------------------------------- | --------------------------------- | -------------
435-
**`MaterialToolbar` title text** | `app:title` | `setTitle`<br>`getTitle` | `null`
436-
**`MaterialToolbar` subtitle text** | `app:subtitle` | `setSubtitle`<br>`getSubtitle` | `null`
437-
**`MaterialToolbar` title color** | `app:titleTextColor` | `setTitleTextColor` | `?android:attr/textColorPrimary`
438-
**`MaterialToolbar` subtitle color** | `app:subtitleTextColor` | `setSubtitleTextColor` | `?android:attr/textColorSecondary`
439-
**`MaterialToolbar` title typography** | `app:titleTextAppearance` | `setTitleTextAppearance` | `?attr/textAppearanceHeadline6`
440-
**`MaterialToolbar` subtitle typography** | `app:subtitleTextAppearance` | `setSubtitleTextAppearance` | `?attr/textAppearanceSubtitle1`
441-
**`MaterialToolbar` title centering** | `app:titleCentered` | `setTitleCentered` | `false`
442-
**`MaterialToolbar` subtitle centering** | `app:subtitleCentered` | `setSubtitleCentered` | `false`
443-
**`CollapsingToolbarLayout` collapsed title typography** | `app:collapsedTitleTextAppearance` | `setCollapsedTitleTextAppearance` | `@style/TextAppearance.AppCompat.Widget.ActionBar.Title`
444-
**`CollapsingToolbarLayout` expanded title typography** | `app:expandedTitleTextAppearance` | `setExpandedTitleTextAppearance` | `@style/TextAppearance.Design.CollapsingToolbar.Expanded`
445-
**`CollapsingToolbarLayout` collapsed title color** | `android:textColor` (in `app:collapsedTitleTextAppearance`) | `setCollapsedTitleTextColor` | `?android:attr/textColorPrimary`
446-
**`CollapsingToolbarLayout` expanded title color** | `android:textColor` (in `app:expandedTitleTextAppearance`) | `setExpandedTitleTextColor` | `?android:attr/textColorPrimary`
447-
**`CollapsingToolbarLayout` expanded title margins** | `app:expandedTitleMargin*` | `setExpandedTitleMargin*` | `32dp`
448-
**`CollapsingToolbarLayout` title max lines** | `app:maxLines` | `setMaxLines`<br>`getMaxLines` | `1`
433+
Element | Attribute | Related method(s) | Default value
434+
-------------------------------------------------------- | -------------------------------------------------------------------------------------------- | --------------------------------- | -------------
435+
**`MaterialToolbar` title text** | `app:title` | `setTitle`<br>`getTitle` | `null`
436+
**`MaterialToolbar` subtitle text** | `app:subtitle` | `setSubtitle`<br>`getSubtitle` | `null`
437+
**`MaterialToolbar` title color** | `app:titleTextColor` | `setTitleTextColor` | `?android:attr/textColorPrimary`
438+
**`MaterialToolbar` subtitle color** | `app:subtitleTextColor` | `setSubtitleTextColor` | `?android:attr/textColorSecondary`
439+
**`MaterialToolbar` title typography** | `app:titleTextAppearance` | `setTitleTextAppearance` | `?attr/textAppearanceHeadline6`
440+
**`MaterialToolbar` subtitle typography** | `app:subtitleTextAppearance` | `setSubtitleTextAppearance` | `?attr/textAppearanceSubtitle1`
441+
**`MaterialToolbar` title centering** | `app:titleCentered` | `setTitleCentered` | `false`
442+
**`MaterialToolbar` subtitle centering** | `app:subtitleCentered` | `setSubtitleCentered` | `false`
443+
**`CollapsingToolbarLayout` collapsed title typography** | `app:collapsedTitleTextAppearance` | `setCollapsedTitleTextAppearance` | `@style/TextAppearance.AppCompat.Widget.ActionBar.Title`
444+
**`CollapsingToolbarLayout` expanded title typography** | `app:expandedTitleTextAppearance` | `setExpandedTitleTextAppearance` | `@style/TextAppearance.Design.CollapsingToolbar.Expanded`
445+
**`CollapsingToolbarLayout` collapsed title color** | `android:textColor` (in `app:collapsedTitleTextAppearance`) or `app:collapsedTitleTextColor` | `setCollapsedTitleTextColor` | `?android:attr/textColorPrimary`
446+
**`CollapsingToolbarLayout` expanded title color** | `android:textColor` (in `app:expandedTitleTextAppearance`) or `app:expandedTitleTextColor` | `setExpandedTitleTextColor` | `?android:attr/textColorPrimary`
447+
**`CollapsingToolbarLayout` expanded title margins** | `app:expandedTitleMargin*` | `setExpandedTitleMargin*` | `32dp`
448+
**`CollapsingToolbarLayout` title max lines** | `app:maxLines` | `setMaxLines`<br>`getMaxLines` | `1`
449449

450450
#### Action items attributes
451451

lib/java/com/google/android/material/appbar/CollapsingToolbarLayout.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
import com.google.android.material.internal.CollapsingTextHelper;
6363
import com.google.android.material.internal.DescendantOffsetUtils;
6464
import com.google.android.material.internal.ThemeEnforcement;
65+
import com.google.android.material.resources.MaterialResources;
6566
import java.lang.annotation.Retention;
6667
import java.lang.annotation.RetentionPolicy;
6768

@@ -253,6 +254,17 @@ public CollapsingToolbarLayout(@NonNull Context context, @Nullable AttributeSet
253254
a.getResourceId(R.styleable.CollapsingToolbarLayout_collapsedTitleTextAppearance, 0));
254255
}
255256

257+
if (a.hasValue(R.styleable.CollapsingToolbarLayout_expandedTitleTextColor)) {
258+
collapsingTextHelper.setExpandedTextColor(
259+
MaterialResources.getColorStateList(
260+
context, a, R.styleable.CollapsingToolbarLayout_expandedTitleTextColor));
261+
}
262+
if (a.hasValue(R.styleable.CollapsingToolbarLayout_collapsedTitleTextColor)) {
263+
collapsingTextHelper.setCollapsedTextColor(
264+
MaterialResources.getColorStateList(
265+
context, a, R.styleable.CollapsingToolbarLayout_collapsedTitleTextColor));
266+
}
267+
256268
scrimVisibleHeightTrigger =
257269
a.getDimensionPixelSize(R.styleable.CollapsingToolbarLayout_scrimVisibleHeightTrigger, -1);
258270

lib/java/com/google/android/material/appbar/res-public/values/public.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
<public name="expandedTitleMarginEnd" type="attr"/>
2626
<public name="expandedTitleMarginBottom" type="attr"/>
2727
<public name="expandedTitleTextAppearance" type="attr"/>
28+
<public name="expandedTitleTextColor" type="attr"/>
2829
<public name="collapsedTitleTextAppearance" type="attr"/>
30+
<public name="collapsedTitleTextColor" type="attr"/>
2931
<public name="contentScrim" type="attr"/>
3032
<public name="statusBarForeground" type="attr"/>
3133
<public name="statusBarScrim" type="attr"/>

lib/java/com/google/android/material/appbar/res/values/attrs.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,12 @@
137137
<!-- The text appearance of the CollapsingToolbarLayouts title when it is fully
138138
'collapsed' -->
139139
<attr name="collapsedTitleTextAppearance" format="reference"/>
140+
<!-- The text color of the CollapsingToolbarLayout's title when it is fully
141+
'expanded' -->
142+
<attr name="expandedTitleTextColor" format="color|reference"/>
143+
<!-- The text color of the CollapsingToolbarLayouts title when it is fully
144+
'collapsed' -->
145+
<attr name="collapsedTitleTextColor" format="color|reference"/>
140146
<!-- The drawable to use as a scrim on top of the CollapsingToolbarLayouts content when
141147
it has been scrolled sufficiently off screen. -->
142148
<attr name="contentScrim" format="color"/>

0 commit comments

Comments
 (0)