Change LinearLayout Opacity when typing in EditText

How to change the LinearLayout opacity when I typing in the EditText? The default opacity of the Layout is set to 0.5 and when I typing in the EditText I want to change the opacity to 1.

This is my LinearLayout.

<LinearLayout
        android:layout_width="240dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="90dp"
        android:layout_gravity="center"
        android:orientation="horizontal"
        android:alpha="0.5"
        android:id="@+id/layoutUsername"
        android:background="@drawable/textedit">

        <bolalob.develops.stud11314025.availaballs.CustomView.CustomFontTextView
            android:id="@+id/iconEmailTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="20dp"
            android:layout_marginTop="18dp"
            android:text="@string/account_icon"
            app:font="@string/font_icon"
            android:textColor="@color/clrline">

        </bolalob.develops.stud11314025.availaballs.CustomView.CustomFontTextView>

        <android.support.design.widget.TextInputLayout
            android:id="@+id/textInputEmail"
            android:layout_width="240dp"
            android:layout_height="48dp"
            android:layout_marginEnd="8dp"
            android:layout_marginLeft="8dp"
            android:layout_marginRight="8dp"
            android:layout_marginStart="8dp"
            android:theme="@style/TextLabelLogin">

            <bolalob.develops.stud11314025.availaballs.CustomView.CustomFontEditTextView
                android:id="@+id/eTEmail"
                android:layout_width="240dp"
                android:layout_height="40dp"
                android:drawablePadding="15dp"
                android:drawableTint="@color/clrline"
                android:textColor="@color/clrpressed"
                android:textColorHighlight="#FFFFFF"
                android:ems="10"
                android:hint="email"
                android:inputType="textEmailAddress"
                android:textSize="12dp"
                android:textStyle="normal"
                android:background="@android:color/transparent"
                app:font="@string/font_roboto" />

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

    </LinearLayout>

Upvotes: 0

Views: 99

Answers (1)

VikasGoyal
VikasGoyal

Reputation: 3376

Add Text Watcher on EditText and change the alpha of LinearLayout with desired behaviour.

View ll= findViewById(R.id.layoutUsername);
    findViewById(R.id.eTEmail). addTextChangedListener(emailWatcher);

    private final TextWatcher emailWatcher = new TextWatcher() {
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
               ll.setAlpha(1.0);
            }

            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            public void afterTextChanged(Editable s) {

                }
            }
        };

Upvotes: 1

Related Questions