How do I make a EditText invisible programmatically

29 Views Asked by At

I have a exitText in my app which starts out invisible that I set that way in the xml file. How do I make it become visible when a button is tapped?

 <EditText
    android:id="@+id/edittext_username"
    android:layout_width="328dp"
    android:layout_height="52dp"
    android:layout_marginStart="32dp"
    android:layout_marginEnd="32dp"
    android:background="#F6F2F2"
    android:backgroundTint="#F6F5F5"

    android:ems="15"
    android:hint="@string/Client_Id"
    android:importantForAutofill="no"
    android:inputType="text"
    android:textAlignment="center"
    android:textColor="#070707"
    android:textColorHint="#0B0A0A"

    android:visibility="visible"

    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    tools:ignore="TextFields" />

this is the button

 findViewById<Button>(R.id.button).setOnClickListener {

  }

how do I make the editView invisible in the button?

1

There are 1 best solutions below

1
Raunit Verma On

change android:visibility="visible" to android:visibility="gone" to do it from the XML.

And if you want to do it programmatically then

findViewById<Button>(R.id.button).visibility=View.GONE