Forum Xamarin.Forms

Text boxes of different colors in the same application

One of the frustrating things about xamarin is that in order to do simple things, you have to make endless mess. my request is very simple some pages of my application contain white text boxes(entry). other pages of my application contain red text boxes(entry).

at the application level this is defined in this way

<item name="colorControlActivated">#fff</item>
<item name="windowActionModeOverlay">true</item>
<item name="colorControlNormal">#fff</item>

in java it is possible to set a different theme to an edittext in a very simple way.


i haven't found the solution to do the same thing with xamarin

with xamarin I created a custom render to turn my text box red

public class EntryGrayRenderer : EditorRenderer
    public EntryGrayRenderer(Context context) : base(context)
    protected override void OnElementPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        base.OnElementPropertyChanged(sender, e);
        if (Control != null)
            if (Build.VERSION.SdkInt < BuildVersionCodes.Lollipop)
                Control.Background.SetColorFilter(Android.Graphics.Color.ParseColor("#a84849"), PorterDuff.Mode.SrcAtop);
                Control.BackgroundTintList = ColorStateList.ValueOf(Android.Graphics.Color.ParseColor("#a84849"));
        IntPtr IntPtrtextViewClass = JNIEnv.FindClass(typeof(TextView));
        IntPtr mCursorDrawableResProperty = JNIEnv.GetFieldID(IntPtrtextViewClass, "mCursorDrawableRes", "I");
        JNIEnv.SetField(Control.Handle, mCursorDrawableResProperty, Resource.Drawable.my_cursor);

is the custom render solution the only one to achieve my purpose?

in any case it was not accepted by my boss because the cursor marker should be red but it remained white.

Do you know how I can overwrite it?


Sign In or Register to comment.