當前位置:首頁 » 安卓系統 » android輸入框限制

android輸入框限制

發布時間: 2025-02-06 10:24:47

❶ android 如何用代碼實現EditText控制項中只能輸入數字

數字<EditText
android:id="@+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number" />
帶小數的數字 <EditText
android:id="@+id/editText3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="numberDecimal" />
電話號碼的 <EditText
android:id="@+id/editText4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="phone" />

❷ android界開發如何禁止密碼輸入框復制粘貼

1、在API-11以下的版本只需要在Xml布局文件或者用代碼把長按屬性設置成false就可以;代碼如下:
editText.setLongClickable(false); // Xml layout file android:longClickable="false"

2、在API-11及以上的話,取消長按就不能完全有效了,最根本的是無效化選擇的操作;代碼如下:
editText.(new ActionMode.Callback() {

@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
return false;
}

@Override
public void onDestroyActionMode(ActionMode mode) {

}

@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
return false;
}

@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
return false;
}
});
注意:EditText在橫屏編輯的時候會出現一個新的不同的編輯界面,這個界面里還是可以復制粘貼的,因此也要取消這個額外的UI:
editText.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI); // android:imeOptions="flagNoExtractUi"

❸ android 中如何限制 EditText 最大輸入字元數

方法一:在 xml 文件中設置文本編輯框屬性作字元數限制,如Android:maxLength="20" 即限制最大輸入字元個數為20;
方法二:
在代碼中使用InputFilter 進行過濾
editText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(20)}); 即限定最大輸入字元數為20

❹ android文本框怎麼樣限制它輸入的只能是阿拉伯數,請各位大俠幫幫忙

設置TextView的這個屬性 android:numeric="integer" 就可以了,當你輸入其他字元時,文本框不讓輸入的,只能是數字

熱點內容
php和javascript 發布:2025-09-19 19:42:11 瀏覽:280
求代數c語言 發布:2025-09-19 19:37:49 瀏覽:712
java循環列印 發布:2025-09-19 19:01:34 瀏覽:67
如何獲得wifi的密碼 發布:2025-09-19 18:39:41 瀏覽:662
伺服器外網內網ip 發布:2025-09-19 18:34:33 瀏覽:836
彈力和壓縮量 發布:2025-09-19 18:30:05 瀏覽:804
二叉樹用數組存儲 發布:2025-09-19 18:20:22 瀏覽:128
老人機的密碼是什麼 發布:2025-09-19 18:05:57 瀏覽:549
已編譯程序的機器代碼 發布:2025-09-19 17:43:29 瀏覽:905
生理與心裡ftp 發布:2025-09-19 17:42:30 瀏覽:887