feat(EditText): 光标染色
This commit is contained in:
parent
63c7ad885c
commit
0a86dffd8e
|
|
@ -2,16 +2,20 @@ package com.huanchengfly.tieba.post.ui.widgets.theme;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.os.Build;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
|
|
||||||
import com.huanchengfly.tieba.post.R;
|
import com.huanchengfly.tieba.post.R;
|
||||||
import com.huanchengfly.tieba.post.ui.common.theme.interfaces.Tintable;
|
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.ColorStateListUtils;
|
||||||
|
import com.huanchengfly.tieba.post.ui.common.theme.utils.ThemeUtils;
|
||||||
import com.huanchengfly.tieba.post.ui.widgets.edittext.widget.UndoableEditText;
|
import com.huanchengfly.tieba.post.ui.widgets.edittext.widget.UndoableEditText;
|
||||||
|
|
||||||
public class TintUndoableEditText extends UndoableEditText implements Tintable {
|
public class TintUndoableEditText extends UndoableEditText implements Tintable {
|
||||||
private int mTextColorResId;
|
private int mTextColorResId;
|
||||||
private int mHintTextColorResId;
|
private int mHintTextColorResId;
|
||||||
|
private int mCursorColorResId;
|
||||||
|
|
||||||
public TintUndoableEditText(Context context) {
|
public TintUndoableEditText(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
|
|
@ -35,12 +39,14 @@ public class TintUndoableEditText extends UndoableEditText implements Tintable {
|
||||||
if (attrs == null) {
|
if (attrs == null) {
|
||||||
mTextColorResId = 0;
|
mTextColorResId = 0;
|
||||||
mHintTextColorResId = 0;
|
mHintTextColorResId = 0;
|
||||||
|
mCursorColorResId = 0;
|
||||||
tint();
|
tint();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
TypedArray array = getContext().obtainStyledAttributes(attrs, R.styleable.TintUndoableEditText, defStyleAttr, 0);
|
TypedArray array = getContext().obtainStyledAttributes(attrs, R.styleable.TintUndoableEditText, defStyleAttr, 0);
|
||||||
mTextColorResId = array.getResourceId(R.styleable.TintUndoableEditText_textColor, 0);
|
mTextColorResId = array.getResourceId(R.styleable.TintUndoableEditText_textColor, 0);
|
||||||
mHintTextColorResId = array.getResourceId(R.styleable.TintUndoableEditText_hintTextColor, 0);
|
mHintTextColorResId = array.getResourceId(R.styleable.TintUndoableEditText_hintTextColor, 0);
|
||||||
|
mCursorColorResId = array.getResourceId(R.styleable.TintUndoableEditText_cursorColor, 0);
|
||||||
array.recycle();
|
array.recycle();
|
||||||
tint();
|
tint();
|
||||||
}
|
}
|
||||||
|
|
@ -53,5 +59,25 @@ public class TintUndoableEditText extends UndoableEditText implements Tintable {
|
||||||
if (mHintTextColorResId != 0) {
|
if (mHintTextColorResId != 0) {
|
||||||
setHintTextColor(ColorStateListUtils.createColorStateList(getContext(), mHintTextColorResId));
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -150,6 +150,7 @@
|
||||||
</declare-styleable>
|
</declare-styleable>
|
||||||
|
|
||||||
<declare-styleable name="TintUndoableEditText">
|
<declare-styleable name="TintUndoableEditText">
|
||||||
|
<attr name="cursorColor" format="color" />
|
||||||
<attr name="hintTextColor" format="color" />
|
<attr name="hintTextColor" format="color" />
|
||||||
<attr name="textColor" />
|
<attr name="textColor" />
|
||||||
</declare-styleable>
|
</declare-styleable>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue