简体   繁体   中英

How to change attributes of controls with MainActivity.java file

<EditText
    android:id="@+id/editText"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ems="10"
    android:hint="Enter Your Name"
    android:inputType="textPassword" />

<Button
    android:id="@+id/button"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/holo_blue_dark"
    android:text="Click Me" />

Now, on the click of a button, I want to change the editText attribute to android:inputType="text"

How can we do this with Java code?

Try like this

EditText edittext = (EditText)findViewById(R.id.editText);

now click of button change the edittext input type like this

edittext.setInputType(InputType.TYPE_CLASS_TEXT);

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