简体   繁体   English

如何使用MainActivity.java文件更改控件的属性

[英]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" 现在,单击按钮,我想将editText属性更改为android:inputType="text"

How can we do this with Java code? 我们如何使用Java代码来做到这一点?

Try like this 这样尝试

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

now click of button change the edittext input type like this 现在单击按钮以更改edittext输入类型

edittext.setInputType(InputType.TYPE_CLASS_TEXT);

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

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