shaoping wang shaoping wang - 7 days ago 5
Android Question

How to change EditText border line color in program code?

enter image description hereActually I have 2 questions.


  1. How to change edittext border line color and size?
    Other answers like use shape.xml to describe the rect detail and set android:background of EditText as @drawable/shape does not work for me, because I need to change focus cursor color too.
    I try to use styles.xml and set colorAccent as the line color, and set EditText android:theme as this. It works for color, but I cannot figure out how to change line size in style.xml.

  2. I want to change the color of EditText at running time, how to change the EditText line color and focus cursor color in program code?



Any help is appreciated! Thanks so much!

I want to change the white line size as 1 dp.

Answer
editText.getBackground().mutate().setColorFilter(getResources().getColor(R.color.AppColor), PorterDuff.Mode.SRC_ATOP);

also android:textCursorDrawable attribute to @null should result in the use of android:textColor as the cursor color.

Use this code in your java class.