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

熱點內容
linux上網代理 發布:2025-03-17 12:23:56 瀏覽:356
c是高級語言嗎 發布:2025-03-17 12:16:31 瀏覽:521
python泛型 發布:2025-03-17 12:15:01 瀏覽:480
編程貓被盜 發布:2025-03-17 12:02:18 瀏覽:130
海關鎖密碼箱如何設置新密碼 發布:2025-03-17 11:53:50 瀏覽:559
農業卡號的密碼在哪裡改 發布:2025-03-17 11:48:57 瀏覽:965
楊瀾超級訪問 發布:2025-03-17 11:47:17 瀏覽:237
資料庫無損連接 發布:2025-03-17 11:47:16 瀏覽:13
memcachephp類 發布:2025-03-17 11:40:04 瀏覽:829
哈夫曼編碼演算法實現 發布:2025-03-17 11:23:31 瀏覽:385