0

I am trying to set transparency to hint colour of floating edittext by setting its alpha value to 0.3.But its not working.I don't see any alpha change in hint colour of editext.

Below is the code

<android.support.design.widget.TextInputLayout
        android:id="@+id/input_number"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/mobile_email"
        android:layout_marginLeft="@dimen/dp15"
        android:layout_marginRight="@dimen/dp15">

        <EditText
            android:id="@+id/number"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:textColor="@color/numxtcolor"
            android:alpha="0.3"
            android:hint="@string/mobilehint"
            android:textSize="@dimen/sp16"
            android:inputType="number"/>

    </android.support.design.widget.TextInputLayout>



    mobilenumber.setOnFocusChangeListener(new View.OnFocusChangeListener() {
                @Override
                public void onFocusChange(View v, boolean hasFocus) {
                    if (hasFocus) {

                        mobilenumber.setAlpha(1);


                    } else {
                                        if (TextUtils.isEmpty(mobilenumber.getText().toString())) {
                            mobilenumber.setAlpha(0.3f);


                        }
                    }
                    mobilenumber.invalidate();
                }
            });
Android Developer
  • 9,157
  • 18
  • 82
  • 139

1 Answers1

0

I think the problem is that you are calling:

mobilenumber.setAlpha(0.3f);

This way, you are setting alpha for the whole view.. And not for the text.

Maybe, you may change your code as follows:

mobilenumber.setOnFocusChangeListener(new View.OnFocusChangeListener() {
    @Override
    public void onFocusChange(View v, boolean hasFocus) {
        if (hasFocus) {
            // Fully opaque WHITE color
            v.setTextColor(Color.parseColor("#FFFFFFFF"));
        } else {
            // 70% transparent color
            if (TextUtils.isEmpty(mobilenumber.getText().toString())) {
                v.setTextColor(Color.parseColor("#55FFFFFF"));
            }
        }
        v.invalidate();
    }
});
guipivoto
  • 18,327
  • 9
  • 60
  • 75