Android EditText 編輯框控制項

2021-09-25 06:31:06 字數 856 閱讀 5334

編輯框(edittext)是 textview 的子類,在 textview 的基礎上增加了文字編輯功能,用於處理使用者輸入,例如登入框等,是非常常用的元件。

在工程 widgetdemo 的 main.xml 檔案中新增乙個 edittext,並實現這個功能:使用者在 edittext 中輸入資訊的同時,用乙個 textview 顯示使用者輸入的資訊。

工程 widgetdemo 中的布局檔案 main.xml 中增加的**如下:

android:id="@+id/edittext1"

android:layout_width="match_parent"

android:layout_height="wrap_content" />

在 widgetdemoactivity 的 oncreate() 方法中新增下列**:

final edittext edittext = (edittext) findviewbyid(r.id.edittext1);

edittext.addtextchangedlistener(new textwatcher()

@override

public void ontextchanged(charsequence s, int start, int before, int count)

@override

public void aftertextchanged(editable s)

});執行結果如圖 1 所示。

圖 1  edittext 的應用介面

android edittext學習記錄

實現在edittext中輸入自定義表情,需要將放在drawable中的表情,嵌入到edittext中,這裡利用imagespan實現該功能。第一步 利用反射機制,得到資源的id,生成bitmap物件 field field r.drawable.class.getdeclaredfield imag...

Android EditText屬性總結

接下來老於就總結一下 edittext屬性吧!android inputtype none 這個就不要解釋了吧 android inputtype text 文字型別,多為大寫 小寫和數字符號 android inputtype textcapcharacters 字母大寫 android inpu...

Android EditText左右滑動

預設的edittext寫滿一行後會自動轉換到下一行,但是我們有時候需要的滿一行後左右滑動過去而不是換行,此時我們可以設定edittext 的屬性 android maxlines 1 即可,如果不可以,則加上 android singleline true android layout width ...