user7346168
user7346168

Reputation: 31

How to make edittext underline transparent white programmatically

View.OnFocusChangeListener focusListener = new View.OnFocusChangeListener() {
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus){
                editText.getBackground().setColorFilter(ContextCompat.getColor(getActivity().getApplicationContext(),R.color.ed_background), PorterDuff.Mode.SRC_ATOP);
            } else {
                int color = Color.parseColor("#FFFFFF");
                editText.getBackground().setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
            }
        }
    };

<color name="ed_background">#33FFFFFF</color>

This makes the edit text underline black, but I want it to be a transparent white. Setting a custom style with xml also sets it to black. How can I make the underline a transparent white with java?

Upvotes: 1

Views: 521

Answers (2)

Abhi Muktheeswarar
Abhi Muktheeswarar

Reputation: 394

Just set the edittext background color to white/transparent in xml layout / in code.

Upvotes: 0

Siarhei
Siarhei

Reputation: 2436

You can try smth like this: creates drawable xml for ex edittext_lined.xml

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:top="-2dp" android:right="-2dp" android:left="-2dp">
    <shape>
      <solid android:color="@android:color/transparent" />
      <stroke android:color="@color/ed_background" android:width="1dp"/>
    </shape>
</item>

then in code:

editText.setBackgroundResource(R.drawable.edittext_lined);

Upvotes: 1

Related Questions