天天看點

Android——文本控件——EditText(文本框)

a.基本資訊及作用

輸入框,用于使用者輸入資訊,為TextView的子類

b.用法

在xml檔案中

<EditText

android:id="@+id/etpasswork"

android:layout_width="wrap_content”

android:layout_height="wrap_content"

android:inputType="textPassword”   //設定輸入資訊的顯示類型(有多種可供選擇,textPassword表示使用者輸入的文本顯示為點)

android:hint="請輸入密碼"   //顯示提示資訊,在使用者輸入資訊後消失

/>

在Java檔案中

private EditText etpassword;

protected void onCreat(Bundle saveInstancestate){

super.onCreat(aveInstanceatate);

setContentView(R.layout.activity_main);

etpassword=(EditText)findViewById(R.id.etpassword);//findbyid方法通過xml中的id把申明控件和xml對應控件相關聯

string password.=etpassword.gettext().tostring();  //得到使用者的輸入資訊

}