問題描述
如果您擁有 Android 手機,您無疑已經(jīng)注意到在某些應(yīng)用程序中,鍵盤布局如何從標準問題變?yōu)閮H數(shù)字或具有 .com
或 .net
基于文本字段輸入類型(例如電話號碼)的特殊按鈕.所以我有兩個問題:
- 如何觸發(fā)此自定義?我懷疑它與
EditText
格式 有關(guān) - 如果我想添加一些自定義按鈕來注入特定模式,是否可以更進一步?假設(shè)我會有一個
AND
按鈕,按下該按鈕會將所有大寫的AND"添加到文本字段中,并用空格包圍.這可以做到嗎? - 我不要問的是如何在 onKeyPress 事件中捕獲一些組合鍵,然后用模式填充文本字段 - 我已經(jīng)知道如何做到這一點了.
它由 android:inputType
XML 屬性(或 setInputType()
方法)控制.
有關(guān)可用選項的信息,請參閱 a>,但我不相信目前有任何方法可以完全自定義鍵盤,但我可能是錯的.
If you own Android phone you are no doubt have noticed how in the certain apps the keyboard layout can change from the standard issue to digits-only or to have .com
or .net
special buttons based on the text field input type (e.g. phone number). So I have 2 questions:
- how to trigger this customization? I suspect it has to do with
EditText
format - Can this be taken even further if I want to add some custom buttons to inject a specific pattern? Say I would have an
AND
button which when pressed will add all uppercase " AND " surrounded by spaces to the text field. Can this be done? - What I'm not asking is how to capture some key combination in onKeyPress event and then populate text field with a pattern - I pretty much know how to do that already.
It is controlled by the android:inputType
XML attribute (or the setInputType()
method).
For info on the available options see the pages for the XML attribute or the object's method.
As an example, the following XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<EditText
android:text="example text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="phone" />
</LinearLayout>
will give you this layout:
whereas changing the inputType
to textEmailAddress
will give you this:
You can customize the "action" button as explained here, but I don't believe there's any way to do full customization of keyboards at this time, but I could be wrong.
這篇關(guān)于Android - 自定義鍵盤按鍵和操作的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!