[android] How to change line color in EditText

You can do it dynamically if you have custom class for edittext.

First of all you have declare state and color of edittext given below.

int[][] states = new int[][]{
                new int[]{-android.R.attr.state_focused}, // enabled
                new int[]{android.R.attr.state_focused}, // disabled
        };
        int[] colors = new int[]{
                secondaryColor,
                primaryColor,
        };

Then Create ColorStateList variable with that

ColorStateList myList = new ColorStateList(states, colors);

Then last step is to assign it to edittext.

editText.setBackgroundTintList(myList);

After this you have to written on focused change event.

this.setOnFocusChangeListener(new OnFocusChangeListener() {
                    @Override
                    public void onFocusChange(View view, boolean b) {
                        setUnderlineColor(selectionColor,deselectionColor);
                    }
                });

And you can make above code inside setUnderlineClor() Method,

private void setUnderlineColor(int primaryColor, int secondaryColor) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        int[][] states = new int[][]{
                new int[]{-android.R.attr.state_focused}, // enabled
                new int[]{android.R.attr.state_focused}, // disabled
        };
        int[] colors = new int[]{
                secondaryColor,
                primaryColor,
        };
        ColorStateList myList = new ColorStateList(states, colors);
        setBackgroundTintList(myList);
    }
}

Examples related to android

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How to implement a simple scenario the OO way My eclipse won't open, i download the bundle pack it keeps saying error log getting " (1) no such column: _id10 " error java doesn't run if structure inside of onclick listener Cannot retrieve string(s) from preferences (settings) strange error in my Animation Drawable how to put image in a bundle and pass it to another activity FragmentActivity to Fragment A failure occurred while executing com.android.build.gradle.internal.tasks

Examples related to xml

strange error in my Animation Drawable How do I POST XML data to a webservice with Postman? PHP XML Extension: Not installed How to add a Hint in spinner in XML Generating Request/Response XML from a WSDL Manifest Merger failed with multiple errors in Android Studio How to set menu to Toolbar in Android How to add colored border on cardview? Android: ScrollView vs NestedScrollView WARNING: Exception encountered during context initialization - cancelling refresh attempt

Examples related to layout

This view is not constrained What's the difference between align-content and align-items? CSS Flex Box Layout: full-width row and columns Fill remaining vertical space with CSS using display:flex What is setContentView(R.layout.main)? How to change line color in EditText Scrolling a flexbox with overflowing content UICollectionView - Horizontal scroll, horizontal layout? How to style a div to be a responsive square? 100% width Twitter Bootstrap 3 template

Examples related to styles

How to manage Angular2 "expression has changed after it was checked" exception when a component property depends on current datetime React Native Border Radius with background color How to change DatePicker dialog color for Android 5.0 How to change line color in EditText Valid values for android:fontFamily and what they map to? Overriding css style? WPF C# button style How to stick <footer> element at the bottom of the page (HTML5 and CSS3)? Binding ConverterParameter CSS align images and text on same line