jasmine mathew
jasmine mathew

Reputation: 127

How can i change editor bottom border line color using custom renderer in xamarin forms

I just only want to change my editor bottom line color to white. No need for rectangle shape.

<?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>

When displaying datepicker in xaml page bottom borderline color is black. I want to change this color to white. How to solve this problem? Is there any custom renderer to set the bottom borderline color?

Upvotes: 2

Views: 1303

Answers (1)

sme
sme

Reputation: 4153

You'll need to create an xml file edittextbottombar.xml and put it in your resources/drawable folder (make sure the build action is Android Resource). Afterwards you can use that file to set the background of the text view.

<?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>

You can set the color to whatever you like, based on the state of the text view.

And in your Android's custom renderer, use it like so:

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

Upvotes: 2

Related Questions