簡體   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" />

現在,單擊按鈕,我想將editText屬性更改為android:inputType="text"

我們如何使用Java代碼來做到這一點?

這樣嘗試

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

現在單擊按鈕以更改edittext輸入類型

edittext.setInputType(InputType.TYPE_CLASS_TEXT);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM