當前位置:首頁 » 安卓系統 » 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" 就可以了,當你輸入其他字元時,文本框不讓輸入的,只能是數字

熱點內容
華為平板怎麼儲存伺服器文件 發布:2025-02-06 12:49:21 瀏覽:479
php查詢結果數組 發布:2025-02-06 12:31:05 瀏覽:714
怎樣把照片壓縮打包 發布:2025-02-06 12:15:19 瀏覽:496
如何編譯java文件 發布:2025-02-06 12:05:58 瀏覽:237
九九乘法編程 發布:2025-02-06 12:05:05 瀏覽:519
台式機忘記開機密碼怎麼辦 發布:2025-02-06 11:58:01 瀏覽:871
android刷新按鈕 發布:2025-02-06 11:57:17 瀏覽:586
存儲過程有輸入參數和輸出參數 發布:2025-02-06 11:55:32 瀏覽:99
成績評選演算法 發布:2025-02-06 11:42:51 瀏覽:997
資料庫測試數據 發布:2025-02-06 11:31:05 瀏覽:824