From 0a86dffd8e43e1356cba68f6cd46f625a7455a0c Mon Sep 17 00:00:00 2001 From: HuanCheng65 <22636177+HuanCheng65@users.noreply.github.com> Date: Thu, 20 Jul 2023 17:59:53 +0800 Subject: [PATCH] =?UTF-8?q?feat(EditText):=20=E5=85=89=E6=A0=87=E6=9F=93?= =?UTF-8?q?=E8=89=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../widgets/theme/TintUndoableEditText.java | 26 +++++++++++++++++++ app/src/main/res/values/attrs.xml | 1 + 2 files changed, 27 insertions(+) diff --git a/app/src/main/java/com/huanchengfly/tieba/post/ui/widgets/theme/TintUndoableEditText.java b/app/src/main/java/com/huanchengfly/tieba/post/ui/widgets/theme/TintUndoableEditText.java index 1c6d7fc8..a6733007 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/ui/widgets/theme/TintUndoableEditText.java +++ b/app/src/main/java/com/huanchengfly/tieba/post/ui/widgets/theme/TintUndoableEditText.java @@ -2,16 +2,20 @@ package com.huanchengfly.tieba.post.ui.widgets.theme; import android.content.Context; import android.content.res.TypedArray; +import android.graphics.drawable.Drawable; +import android.os.Build; import android.util.AttributeSet; import com.huanchengfly.tieba.post.R; import com.huanchengfly.tieba.post.ui.common.theme.interfaces.Tintable; import com.huanchengfly.tieba.post.ui.common.theme.utils.ColorStateListUtils; +import com.huanchengfly.tieba.post.ui.common.theme.utils.ThemeUtils; import com.huanchengfly.tieba.post.ui.widgets.edittext.widget.UndoableEditText; public class TintUndoableEditText extends UndoableEditText implements Tintable { private int mTextColorResId; private int mHintTextColorResId; + private int mCursorColorResId; public TintUndoableEditText(Context context) { super(context); @@ -35,12 +39,14 @@ public class TintUndoableEditText extends UndoableEditText implements Tintable { if (attrs == null) { mTextColorResId = 0; mHintTextColorResId = 0; + mCursorColorResId = 0; tint(); return; } TypedArray array = getContext().obtainStyledAttributes(attrs, R.styleable.TintUndoableEditText, defStyleAttr, 0); mTextColorResId = array.getResourceId(R.styleable.TintUndoableEditText_textColor, 0); mHintTextColorResId = array.getResourceId(R.styleable.TintUndoableEditText_hintTextColor, 0); + mCursorColorResId = array.getResourceId(R.styleable.TintUndoableEditText_cursorColor, 0); array.recycle(); tint(); } @@ -53,5 +59,25 @@ public class TintUndoableEditText extends UndoableEditText implements Tintable { if (mHintTextColorResId != 0) { setHintTextColor(ColorStateListUtils.createColorStateList(getContext(), mHintTextColorResId)); } + if (mCursorColorResId != 0) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + Drawable drawable; + drawable = getTextCursorDrawable(); + if (drawable == null) { + return; + } + setTextCursorDrawable(ThemeUtils.tintDrawable(drawable, ColorStateListUtils.createColorStateList(getContext(), mCursorColorResId))); + } + } + } + + public void setTextColorResId(int textColorResId) { + mTextColorResId = textColorResId; + tint(); + } + + public void setHintTextColorResId(int hintTextColorResId) { + mHintTextColorResId = hintTextColorResId; + tint(); } } diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml index 8c98a471..2a37fdb5 100644 --- a/app/src/main/res/values/attrs.xml +++ b/app/src/main/res/values/attrs.xml @@ -150,6 +150,7 @@ +