【问题标题】:How can i change editor bottom border line color using custom renderer in xamarin forms如何在 xamarin 表单中使用自定义渲染器更改编辑器底部边框线颜色
【发布时间】:2018-02-01 11:07:02
【问题描述】:

我只想将我的编辑器底线颜色更改为白色。不需要矩形。

<?xml version="1.0" encoding="utf-8"?>
<xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <!-- Draw a 2dp width border around shape -->
            <stroke
                android:color="#ff1e0c"
                android:bottom="2dp"/>
        </shape>
    </item>

当在 xaml 页面中显示日期选择器时,底部边框颜色为黑色。我想把这个颜色改成白色。如何解决这个问题呢?是否有任何自定义渲染器来设置底部边框颜色?

【问题讨论】:

    标签: xamarin


    【解决方案1】:

    您需要创建一个 xml 文件 edittextbottombar.xml 并将其放在您的 resources/drawable 文件夹中(确保构建操作是 Android Resource)。之后您可以使用该文件来设置文本视图的背景。

    <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
        <item
            android:bottom="1.5dp"
            android:left="-1.5dp"
            android:right="-1.5dp"
            android:top="-1.5dp">
            <selector>
                <item
                    android:state_enabled="true"
                    android:state_focused="true">
                    <shape android:shape="rectangle">
                        <stroke
                            android:width=".5dp"
                            android:color="@color/editTextUnderlineFocused" />
                    </shape>
                </item>
                <item android:state_enabled="true">
                    <shape android:shape="rectangle">
                        <stroke
                            android:width=".5dp"
                            android:color="@color/editTextUnderlineUnfocused" />
                    </shape>
                </item>
            </selector>
        </item>
    </layer-list>
    

    您可以根据文本视图的状态将颜色设置为您喜欢的任何颜色。

    在你的 Android 的自定义渲染器中,像这样使用它:

    Control.SetBackground(Resources.GetDrawable(Resource.Drawable.edittextbottombar));

    【讨论】:

    • 这在 Android 中运行良好,知道如何在 iOS 中实现吗?
    猜你喜欢
    • 2020-10-19
    • 1970-01-01
    • 2021-05-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多