简体   繁体   中英

How do I make a EditText invisible programmatically

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM