void ConfigureControl() { EditText editText; if (Control is EditText) { editText = (EditText)Control; } else { return; } Drawable clearDrawable = ApiSafe.GetDrawable(Resource.Mipmap.ic_clear); Drawable clearDrawablePressed = clearDrawable.GetConstantState().NewDrawable().Mutate(); // Icon opacity: https://material.io/guidelines/style/icons.html clearDrawable.SetAlpha(54); clearDrawablePressed.SetAlpha(87); var stateListDrawable = new StateListDrawable(); // Pressed State stateListDrawable.AddState(new int[] { global::Android.Resource.Attribute.StatePressed }, clearDrawablePressed); // Default State stateListDrawable.AddState(new int[] { }, clearDrawable); editText.SetCompoundDrawablesWithIntrinsicBounds(null, null, stateListDrawable, null); editText.SetOnTouchListener(new OnClearEntryTouchListener()); }
public OnShowHidePassTouchListener() { visibilityDrawable = ApiSafe.GetDrawable(Resource.Mipmap.ic_visibility); visibilityDrawable.SetAlpha(54); visibilityOffDrawable = ApiSafe.GetDrawable(Resource.Mipmap.ic_visibility_off); visibilityOffDrawable.SetAlpha(54); }
void ConfigureControl() { EditText editText; if (Control is EditText) { editText = (EditText)Control; } else { return; } Drawable visibilityOffDrawable = ApiSafe.GetDrawable(Resource.Mipmap.ic_visibility_off); // Icon opacity: https://material.io/guidelines/style/icons.html visibilityOffDrawable.SetAlpha(54); // IntrinsicWidth/Height provides the default height or width of that drawable // https://developer.android.com/reference/android/graphics/drawable/Drawable.html#getIntrinsicHeight() editText.SetCompoundDrawablesWithIntrinsicBounds(null, null, visibilityOffDrawable, null); editText.TransformationMethod = PasswordTransformationMethod.Instance; editText.SetOnTouchListener(new OnShowHidePassTouchListener()); }