mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-23 04:28:35 +00:00
Fix NullPointerException if there is no cursor drawable set.
This commit is contained in:
committed by
Greyson Parrelli
parent
c1b54b3532
commit
3c748b2df6
@@ -9,6 +9,7 @@ import android.widget.EditText;
|
|||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import androidx.annotation.ColorInt;
|
import androidx.annotation.ColorInt;
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -26,10 +27,15 @@ public final class EditTextUtil {
|
|||||||
text.setFilters(filters.toArray(new InputFilter[0]));
|
text.setFilters(filters.toArray(new InputFilter[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setCursorColor(EditText text, @ColorInt int colorInt) {
|
public static void setCursorColor(@NonNull EditText text, @ColorInt int colorInt) {
|
||||||
if (Build.VERSION.SDK_INT >= 29) {
|
if (Build.VERSION.SDK_INT >= 29) {
|
||||||
Drawable cursorDrawable = text.getTextCursorDrawable().mutate();
|
Drawable drawable = text.getTextCursorDrawable();
|
||||||
|
|
||||||
|
if (drawable == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Drawable cursorDrawable = drawable.mutate();
|
||||||
cursorDrawable.setColorFilter(new PorterDuffColorFilter(colorInt, PorterDuff.Mode.SRC_IN));
|
cursorDrawable.setColorFilter(new PorterDuffColorFilter(colorInt, PorterDuff.Mode.SRC_IN));
|
||||||
text.setTextCursorDrawable(cursorDrawable);
|
text.setTextCursorDrawable(cursorDrawable);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user