同一应用程序中不同颜色的文本框

问题描述

关于xamarin的令人沮丧的事情之一是,为了做简单的事情,您必须无休止地混乱。 我的要求很简单 我的应用程序的某些页面包含白色文本框(条目)。 我的应用程序的其他页面包含红色文本框(条目)。

在应用程序级别上是以这种方式定义的

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

在Java中,可以通过非常简单的方式为edittext设置不同的主题

<EditText
    android:layout_width="match_parent"
    android:theme="@style/AppTheme.EditText"
/>

我还没有找到使用xamarin做相同事情的解决方

使用xamarin创建了一个自定义渲染器,将文本框变成红色

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);
                }
                else
                {
                    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);
        }
    }

自定义渲染解决方案是唯一实现我目的的解决方案吗?

无论如何,我的老板都不接受它,因为光标标记应为红色,但仍为白色。

enter image description here

您知道我该如何覆盖它吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)