From 4021284ad681376ab24f7a8d860825073a0e79eb Mon Sep 17 00:00:00 2001
From: Ishan09811 <156402647+Ishan09811@users.noreply.github.com>
Date: Wed, 12 Feb 2025 13:27:37 +0530
Subject: [PATCH 1/3] MaterialToolbar: Implement marquee logic
---
.../material/appbar/MaterialToolbar.java | 34 +++++++++++++++++++
1 file changed, 34 insertions(+)
diff --git a/lib/java/com/google/android/material/appbar/MaterialToolbar.java b/lib/java/com/google/android/material/appbar/MaterialToolbar.java
index 347c55af0bc..2c60a830346 100644
--- a/lib/java/com/google/android/material/appbar/MaterialToolbar.java
+++ b/lib/java/com/google/android/material/appbar/MaterialToolbar.java
@@ -83,6 +83,7 @@ public class MaterialToolbar extends Toolbar {
@Nullable private Integer navigationIconTint;
private boolean titleCentered;
private boolean subtitleCentered;
+ private boolean titleMarqueeEnabled;
@Nullable private ImageView.ScaleType logoScaleType;
@Nullable private Boolean logoAdjustViewBounds;
@@ -110,6 +111,7 @@ public MaterialToolbar(@NonNull Context context, @Nullable AttributeSet attrs, i
titleCentered = a.getBoolean(R.styleable.MaterialToolbar_titleCentered, false);
subtitleCentered = a.getBoolean(R.styleable.MaterialToolbar_subtitleCentered, false);
+ titleMarqueeEnabled = a.getBoolean(R.styleable.MaterialToolbar_titleMarqueeEnabled, false);
final int index = a.getInt(R.styleable.MaterialToolbar_logoScaleType, -1);
if (index >= 0 && index < LOGO_SCALE_TYPE_ARRAY.length) {
@@ -144,6 +146,7 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto
maybeCenterTitleViews();
updateLogoImageView();
+ enableMarqueeIfNeeded();
}
private void maybeCenterTitleViews() {
@@ -228,6 +231,19 @@ private void updateLogoImageView() {
}
}
+ private void enableMarqueeIfNeeded() {
+ if (!titleMarqueeEnabled) return;
+
+ TextView titleTextView = ToolbarUtils.getTitleTextView(this);
+ if (titleTextView != null) {
+ titleTextView.setEllipsize(android.text.TextUtils.TruncateAt.MARQUEE);
+ titleTextView.setSingleLine(true);
+ titleTextView.setSelected(true);
+ titleTextView.setFocusable(true);
+ titleTextView.setFocusableInTouchMode(true);
+ }
+ }
+
/**
* Returns scale type of logo's ImageView
*
@@ -347,6 +363,24 @@ public boolean isTitleCentered() {
return titleCentered;
}
+ /**
+ * Sets whether the title text corresponding to the {@link #setTitle(int)} method should be
+ * marquee.
+ */
+ public void setTitleMarqueeEnabled(boolean enabled) {
+ this.titleMarqueeEnabled = enabled;
+ requestLayout();
+ }
+
+ /**
+ * Returns whether the title text corresponding to the {@link #setTitle(int)} method is marquee or not.
+ *
+ * @see #setTitleMarqueeEnabled(boolean)
+ */
+ public boolean isTitleMarqueeEnabled() {
+ return titleMarqueeEnabled;
+ }
+
/**
* Sets whether the subtitle text corresponding to the {@link #setSubtitle(int)} method should be
* centered horizontally within the toolbar.
From 234c8261597eff4dbfe40e538f97ced47125d9d9 Mon Sep 17 00:00:00 2001
From: Ishan09811 <156402647+Ishan09811@users.noreply.github.com>
Date: Wed, 12 Feb 2025 13:30:53 +0530
Subject: [PATCH 2/3] public: Add ``titleMarqueeEnabled`` attribute
---
.../google/android/material/appbar/res-public/values/public.xml | 1 +
1 file changed, 1 insertion(+)
diff --git a/lib/java/com/google/android/material/appbar/res-public/values/public.xml b/lib/java/com/google/android/material/appbar/res-public/values/public.xml
index e2bb35dc985..bf6b05643fc 100644
--- a/lib/java/com/google/android/material/appbar/res-public/values/public.xml
+++ b/lib/java/com/google/android/material/appbar/res-public/values/public.xml
@@ -93,6 +93,7 @@
+
From 9807d04982869bce62548fc518ebc26a40c14df7 Mon Sep 17 00:00:00 2001
From: Ishan09811 <156402647+Ishan09811@users.noreply.github.com>
Date: Mon, 3 Mar 2025 11:45:14 +0530
Subject: [PATCH 3/3] TopAppBar: update docs
---
docs/components/TopAppBar.md | 1 +
1 file changed, 1 insertion(+)
diff --git a/docs/components/TopAppBar.md b/docs/components/TopAppBar.md
index 7b36fa33703..762c92dc818 100644
--- a/docs/components/TopAppBar.md
+++ b/docs/components/TopAppBar.md
@@ -387,6 +387,7 @@ Element | Attr
**`MaterialToolbar` title typography** | `app:titleTextAppearance` | `setTitleTextAppearance` | `?attr/textAppearanceTitleLarge`
**`MaterialToolbar` subtitle typography** | `app:subtitleTextAppearance` | `setSubtitleTextAppearance` | `?attr/textAppearanceTitleMedium`
**`MaterialToolbar` title centering** | `app:titleCentered` | `setTitleCentered` | `false`
+**`MaterialToolbar` title marquee** | `app:titleMarqueeEnabled` | `setTitleMarqueeEnabled` | `false`
**`MaterialToolbar` subtitle centering** | `app:subtitleCentered` | `setSubtitleCentered` | `false`
**`CollapsingToolbarLayout` collapsed title typography** | `app:collapsedTitleTextAppearance` | `setCollapsedTitleTextAppearance` | `?attr/textAppearanceTitleLarge`
**`CollapsingToolbarLayout` expanded title typography** | `app:expandedTitleTextAppearance` | `setExpandedTitleTextAppearance` | `?attr/textAppearanceHeadlineSmall` for Medium`?attr/textAppearanceHeadlineMedium` for Large