Created
December 2, 2019 14:51
-
-
Save Sa1Gur/d0e320ab1ad1fea5c08f7322601c2b05 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e) | |
{ | |
base.OnElementChanged(e); | |
if (Control == null || e.NewElement == null) return; | |
if (e.NewElement is MyMaterialEntry customEntry) | |
{ | |
EditText.SetHighlightColor(color: customEntry.MyHighlightColor.ToAndroid()); | |
try | |
{ | |
JNIEnv.SetField(EditText.Handle, JNIEnv.GetFieldID(JNIEnv.FindClass(typeof(TextView)), "mCursorDrawableRes", "I"), 0); | |
using (var textViewTemplate = new TextView(EditText.Context)) | |
{ | |
var field = textViewTemplate.Class.GetDeclaredField("mEditor"); | |
field.Accessible = true; | |
var editor = field.Get(EditText); | |
string[] | |
fieldsNames = { "mTextSelectHandleLeftRes", "mTextSelectHandleRightRes", "mTextSelectHandleRes" }, | |
drawablesNames = { "mSelectHandleLeft", "mSelectHandleRight", "mSelectHandleCenter" }; | |
for (int index = 0; index < fieldsNames.Length && index < drawablesNames.Length; index++) | |
{ | |
field = textViewTemplate.Class.GetDeclaredField(fieldsNames[index]); | |
field.Accessible = true; | |
Drawable handleDrawable = ContextCompat.GetDrawable(Context, field.GetInt(EditText)); | |
handleDrawable.SetColorFilter(new PorterDuffColorFilter(customEntry.MyHighlightColor.ToAndroid(), PorterDuff.Mode.SrcIn)); | |
field = editor.Class.GetDeclaredField(drawablesNames[index]); | |
field.Accessible = true; | |
field.Set(editor, handleDrawable); | |
} | |
} | |
} | |
catch (NoSuchFieldError) | |
{ | |
} | |
catch (NoSuchFieldException) | |
{ | |
} | |
catch (ReflectiveOperationException) | |
{ | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment