微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决同一应用程序中不同颜色的文本框

关于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 举报,一经查实,本站将立刻删除。