Sachin K Pissay
Sachin K Pissay

Reputation: 693

how to change the edit text bottom line color in android?

Hi I am doing a login page for my project whose xml looks like this


            <EditText 
                android:id="@+id/user_name_id"
                android:layout_height="wrap_content"
                android:layout_width="300dp"
                android:ems="10"
                android:singleLine="true"
                android:layout_gravity="top|center"
                android:gravity="center"
                android:layout_marginTop="200dp"
                android:hint=" Email Address"
                android:textColor="#B3B3B3"
                android:textColorHint="#B3B3B3"
                android:textCursorDrawable="@drawable/color_cursor"
                />

The about code shows that text, hint and the cursor are in #b3b3b3 color code. and i wanted the bottom line also in the same color code. I tried using selectors also as shown below. but dint work out for me. please suggest a genuine method to particularly change the bottom line color of edittext.

                    <selector 
                    xmlns:android="http://schemas.android.com/apk/res/android"
                    >
                    <item 
                        android:state_pressed="true"
                        android:drawable="@android:drawable/edittext_pressed" 
                        /> <!-- pressed -->    
                    <item 
                        android:state_focused="true"
                        android:drawable="@drawable/edittext_focused_blue" 
                        /> <!-- focused -->    
                    <item 
                        android:drawable="@android:drawable/edittext_normal" 
                        /> <!-- default -->
                    </selector>

and i used the below code in the xml to change the cursor color

            <?xml version="1.0" encoding="utf-8"?>
            <shape xmlns:android="http://schemas.android.com/apk/res/android" >
                <size android:width="1dp" />
                <solid android:color="#B3B3B3"  />
            </shape> 

or else can anyone please modifify the below code for me

            <resources>

                <!--
                    Base application theme, dependent on API level. This theme is replaced
                    by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
                -->
                <style name="AppBaseTheme" parent="Theme.AppCompat.Light">
                    <!--
                        Theme customizations available in newer API levels can go in
                        res/values-vXX/styles.xml, while customizations related to
                        backward-compatibility can go here.
                    -->
                </style>

                <!-- Application theme. -->
                <style name="AppTheme" parent="AppBaseTheme">
                    <!-- All customizations that are NOT specific to a particular API-level can go here. -->
                </style>

            </resources>

Upvotes: 0

Views: 2621

Answers (3)

Sachin K Pissay
Sachin K Pissay

Reputation: 693

I was using api level 21 (lollypop) and i have found a solution for this as this solution works only for api levels 21 and above. Using layer-list

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

<item>
    <shape android:shape="line" >
        <solid android:color="#B3B3B3" />
    </shape>
</item>

<item android:top="-2dp" android:right="-2dp" android:left="-2dp">
    <shape>
        <solid android:color="@android:color/transparent" />
        <stroke
            android:width="0.1dp"
            android:color="#B3B3B3" />
    </shape>
</item>

</layer-list>

If used for api levels below 21 then it gives an exception.

Upvotes: 1

rajahsekar
rajahsekar

Reputation: 914

Use app-compact library

<style name="Theme.App.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorControlNormal">#c5c5c5</item>
<item name="colorControlActivated">@color/accent</item>
<item name="colorControlHighlight">@color/accent</item>

Now Edittext line color will change in your app.

Upvotes: 0

Tom
Tom

Reputation: 7804

If you're using the v21+ (lollipo) support library, you can set colorAccent in your app's theme:

<style name="Theme.MyTheme" parent="Theme.AppCompat.Light">
    ...
    <item name=”colorAccent”>@color/accent</item> 
    ...
</style>

Upvotes: 0

Related Questions