當前位置:首頁 » 安卓系統 » android輸入數字

android輸入數字

發布時間: 2023-07-27 01:33:08

① android 中怎麼控制EditText只能輸入數字和字母,不能有漢字,字元

例子如下:
strings.xml文件:
<string name="rule_password">`¬!"£$%^*()~=#{}[];':,./?/*-_+<>@&</string>
EditText的布局文件:

<EditText android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:digits="@string/rule_password"/>
註:在strings.xml中不能直接寫特殊符號,如@&等特殊符號,可使用ASCII碼表示。
<的ASCII碼為 <
>的ASCII碼為 >

@的ASCII碼為 @
&的ASCII碼為 &

② android 中怎麼控制EditText只能輸入數字和字母

在EditText中設置屬性,android:numeric="integer"即只能輸入整數,如

<EditText
android:id="@+id/home_et_validate"
style="@style/order_vcode_input"
android:hint="請輸入訂單驗證碼"
android:inputType="number"
android:digits="@string/filter_vcode"/>
<stringname="filter_vcode"></string>

解釋說明:

注意其中的android:digits=""
這個就是限制輸入類型的。

安卓手機怎麼設置默認數字軟鍵盤

1、首先需要打開手機上的設置,點擊語言和輸入法。

④ 如何實現android EditText允許輸入字母和數字,同時默認彈出數字鍵盤

這個問題看似簡單,不過由於Android輸入法的開放性,許多輸入法相關的參數設置是由第三方輸入法來實現的,而第三方輸入法眾多、實現不一,導致這個問題變得很復雜。
結論是,目前來看,並沒有直接的方法,可以對所有輸入法實現上述需求。
不過針對這個問題,我們有以下幾種處理方案:

設置android:digits屬性,允許輸入數字和字母。
設置android:inputType為"number",將鍵盤切換為數字鍵盤。
這里的關鍵是,雖然單獨設置android:inputType="number"時,只允許輸入數字;但同時設置android:inputType和android:digits時,允許輸入的字元是以android:digits為準的。

當輸入法本身的UI允許在數字鍵盤、字母鍵盤間切換時,該方案是有效的;但是一些輸入法的數字鍵盤不能切換到字母鍵盤,該方案失效;特別是,Android5.0的原生輸入法就是如此,數字鍵盤UI沒有提供切換到其他鍵盤的按鈕。

雖然該方案對一些輸入法(尤其是英文輸入法)無效,但是中文輸入法基本都是有效的。如果APP僅在國內用的,這個方案夠用了

方案一失效的主要原因是,輸入法界面中沒有提供切換鍵盤的按鍵,所以我們可以自己添上按鍵。
帶來的問題是,自己添加按鍵,很難與輸入法保持統一的UI風格;而當輸入法本身有鍵盤切換按鍵時,這個方案是畫蛇添足,既怪異又不美觀。 所以這個方案在UI上有嚴重缺陷,並不實用。
效果圖如下:

Activity如下:

activity_main.xml如下:

自定義鍵盤可以徹底解決問題,是最完美的方案;但是復雜度有點高。

默認彈出數字鍵盤真的有那麼重要麼?沒有的話,乾脆不要折騰了,StackOverflow上那麼多人已經證明這個問題無完美解了。

⑤ android開發EditText輸入時彈出數字輸入鍵盤

一共有兩種方法:
1.可以直接在布局文件中設置輸入文本類型為數字
<EditText

android:id="@+id/editview"

android:layout_width="match_parent"

android:layout_height="wrap_content"
android:inputType="number"
android:hint="請輸入數字"/>
2.代碼設置:
( EditText) et = (EditText) findViewById(R.id.editview);
ed.setInputType(InputType.TYPE_CLASS_NUMBER);

⑥ 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" />

熱點內容
安卓哪裡填寫apple代碼 發布:2025-02-05 00:28:54 瀏覽:287
oppo手機鎖屏密碼忘記後如何更換 發布:2025-02-05 00:28:19 瀏覽:24
幼兒思維編程 發布:2025-02-05 00:18:21 瀏覽:24
我的世界電腦正版如何進入伺服器 發布:2025-02-05 00:18:06 瀏覽:878
疫情防控健康碼預警機制演練腳本 發布:2025-02-04 23:58:46 瀏覽:38
分治演算法java 發布:2025-02-04 23:41:15 瀏覽:592
安卓app點進去就閃退怎麼回事 發布:2025-02-04 23:36:56 瀏覽:779
宏按鍵編程 發布:2025-02-04 23:05:11 瀏覽:904
微信隱形密碼在哪裡設置 發布:2025-02-04 23:05:01 瀏覽:866
android的補間動畫 發布:2025-02-04 23:03:42 瀏覽:416