1

I have a dialog layout in that i have 3 edit texts, for the 1st edit text it shows the underline color as green(primary color), and other two edit text shows the color pink(color accent).

enter image description here

Why so? It should be same as other two edit texts.

Tried to change this with :

 name.getBackground().mutate().setColorFilter(getResources().getColor(R.color.colorAccent), PorterDuff.Mode.SRC_ATOP);
                name.getBackground().setColorFilter(getResources().getColor(R.color.colorAccent), PorterDuff.Mode.SRC_ATOP);

also by the SO solutions. But nothing helped.

<style name="AppBaseTheme" parent="Theme.AppCompat.Light">

        ....
        <item name="android:editTextStyle">@style/EditTextStyle</item>
</style>

<style name="EditTextStyle" parent="Widget.AppCompat.EditText">
         <item name="colorControlNormal">@color/border_gray</item>
         <item name="colorControlActivated">@color/border_gray</item>
         <item name="colorControlHighlight">@color/border_gray</item>
</style>

layout :

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical">

    <LinearLayout android:layout_height="50dp"
        android:layout_width="match_parent"
        android:background="@color/colorPrimary">


        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Add Schedule"
            android:textColor="@android:color/white"
            android:textAppearance="@android:style/TextAppearance.Medium"
            android:layout_gravity="center"
            android:layout_marginLeft="20dp" />

    </LinearLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingBottom="20dp">


        <EditText
            android:id="@+id/edt_name"
            android:layout_width="match_parent"
            android:layout_height="45dp"
            android:textColor="#000000"
            android:textSize="14sp"
            android:inputType="textCapSentences"
            android:hint="Name"
            android:cursorVisible="false"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:layout_marginTop="20dp" />

        <EditText
            android:id="@+id/edt_dateTime"
            android:layout_width="match_parent"
            android:layout_height="45dp"
            android:textColor="#000000"
            android:textSize="14sp"
            android:cursorVisible="false"
            android:inputType="textCapSentences"
            android:hint="Date and Time"
            android:layout_centerVertical="true"
            android:layout_alignLeft="@+id/edt_name"
            android:layout_alignStart="@+id/edt_name"
            android:layout_below="@+id/edt_name"
            android:layout_alignRight="@+id/edt_name"
            android:layout_alignEnd="@+id/edt_name"
            android:layout_marginTop="05dp" />

        <EditText
            android:id="@+id/edt_budget"
            android:layout_width="match_parent"
            android:layout_height="45dp"
            android:textColor="#000000"
            android:textSize="14sp"
            android:cursorVisible="false"
            android:hint="Budget"
            android:layout_below="@+id/edt_dateTime"
            android:layout_alignLeft="@+id/edt_dateTime"
            android:layout_alignStart="@+id/edt_dateTime"
            android:layout_alignRight="@+id/edt_dateTime"
            android:layout_alignEnd="@+id/edt_dateTime"
            android:layout_marginTop="05dp"
            android:inputType="number" />

    </RelativeLayout>

</LinearLayout>

This is what i got after implementing drawable.

enter image description here

Thank you..

Dhaval Patel
  • 10,119
  • 5
  • 43
  • 46

6 Answers6

1

It simply consists of overriding the value for colorControlActivated, colorControlHighlight and colorControlNormal in your app theme definition

<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>
    </style>

or by java

editText.getBackground().mutate().setColorFilter(getResources().getColor(R.color.your_color), PorterDuff.Mode.SRC_ATOP);
user2934536
  • 149
  • 8
1

by changing your "colorAccent" color you will change color or edittext bottom line and text input layout as well.

Naitik
  • 796
  • 11
  • 32
1

Create textfield_bg_drawable.xml in drawable folder. and set it as background resource in EditText.

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:bottom="2dp"
        android:left="-2dp"
        android:right="-2dp"
        android:top="-2dp">
        <selector>
            <item
                android:state_enabled="true"
                android:state_focused="true">
                <shape android:shape="rectangle">
                    <stroke
                        android:width="2dp"
                        android:color="@color/focused_line_color" />
                </shape>
            </item>
            <item android:state_enabled="true">
                <shape android:shape="rectangle">
                    <stroke
                        android:width="1dp"
                        android:color="@color/normal_line_color" />
                </shape>
            </item>
        </selector>
    </item>
</layer-list>
Dhaval Patel
  • 10,119
  • 5
  • 43
  • 46
  • What's wrong with this? As I used this drawable I stated the color as accent color, Still it shows me the green color. My accent color is pink. Frustrating :-( @Dhaval Patel –  May 24 '16 at 12:07
  • Have you set drawable `android:background="@drawable/textfield_bg_drawable"` in EditText or in Style? – Dhaval Patel May 24 '16 at 12:12
  • Try Clean and Rebuild. – Dhaval Patel May 24 '16 at 12:13
  • tried. also did invalid caches ans restart. @Dhaval Patel –  May 24 '16 at 12:14
  • please check the added screen shot in question. For both the edit texts I am using same drawable. Still they are different. @Dhaval Patel –  May 24 '16 at 12:23
  • Are you doing any work on EditText1 programmatically? Check whether you are applying Color-Filter or not? – Dhaval Patel May 24 '16 at 12:34
  • Remove `name.getBackground().mutate().setColorFilter(getResources().getColor(R.color.colorAccent), PorterDuff.Mode.SRC_ATOP);` line if it's still present. – Dhaval Patel May 24 '16 at 12:37
  • yes i had some code to set it as green. got it. thank you.. @Dhaval Patel –  May 24 '16 at 12:46
  • Glad the solution worked. Would you mind accepting this answer? It might help people experiencing a similar issue and will help getting your question noticed. – Dhaval Patel May 24 '16 at 12:49
0

Try with this following code properly working on my side

        Drawable drawable = editText.getBackground(); // get current EditText drawable
        drawable.setColorFilter(Color.GREEN, PorterDuff.Mode.SRC_ATOP); // change the drawable color

        if (Build.VERSION.SDK_INT > 16) {
            editText.setBackground(drawable); // set the new drawable to EditText
        } else {
            editText.setBackgroundDrawable(drawable); // use setBackgroundDrawable because setBackground required API 16
        }

Where editText is the id of your EditText

Dhiraj
  • 870
  • 2
  • 12
  • 25
  • @user6265109 actually it is working on my side do you get any error ?? – Dhiraj May 24 '16 at 11:45
  • @user6265109 please have a look with this link http://android--code.blogspot.in/2015/08/android-edittext-bottom-border-color.html – Dhiraj May 24 '16 at 12:12
  • What's wrong with this? As I used this drawable I stated the color as accent color, Still it shows me the green color. My accent color is pink. Frustrating @Dhiraj –  May 24 '16 at 12:16
  • @user6265109 what output you got when you tried with my code – Dhiraj May 24 '16 at 12:16
  • it shows the full edit text as green though i have given the color accent i.e. pink. it dose not set the color to bottom line. That's the thing also for the first edit text only it shows the green color, i tried with both edit texts for second edit text it shows the bottom line as pink but not for the first? What's wrong? :-( @Dhiraj –  May 24 '16 at 12:20
  • check the added screen shot in question . @Dhiraj –  May 24 '16 at 12:22
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/112787/discussion-between-dhiraj-and-user6265109). – Dhiraj May 24 '16 at 12:22
  • @user6265109 which color you want to give to bottom line?? – Dhiraj May 24 '16 at 12:25
  • accent color i.e pink. @Dhiraj –  May 24 '16 at 12:25
  • I don't want the edit text's bottom line as pink at normal, when we click on edit text it's color changes to pink for both bottom edit text's, but for first it's green at normal also and after selecting also. @Dhiraj –  May 24 '16 at 12:28
0

I think it is because Your 1st editText focusing, when your alert layout appear.

add this line in your editText

android:focusable="true"
sivaBE35
  • 1,876
  • 18
  • 23
0

You need to disable focus from your first edittext when the activity is opened, so set android:requestFocus= "false"

in your xml file. Or try the following

edittext.clearFocus();

in your java file.

It will not pick your primary color then.

Hope it works!