简体   繁体   English

如何以编程方式使 EditText 不可见

[英]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.我的应用程序中有一个 exitText,它一开始是不可见的,我在 xml 文件中设置了这种方式。 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?如何使按钮中的editView不可见?

change android:visibility="visible" to android:visibility="gone" to do it from the XML.android:visibility="visible"更改为android:visibility="gone"以从 XML 执行此操作。

And if you want to do it programmatically then如果你想以编程方式进行,那么

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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