自定义键盘按键和操作

自定义键盘按键和操作

本文介绍了Android - 自定义键盘按键和操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您拥有 Android 手机,您无疑已经注意到在某些应用程序中,键盘布局如何从标准问题变为仅数字或具有 .com.net 基于文本字段输入类型(例如电话号码)的特殊按钮.所以我有两个问题:

  1. 如何触发此自定义?我怀疑它与 EditText 格式
  2. 有关
  3. 如果我想添加一些自定义按钮来注入特定模式,是否可以更进一步?假设我会有一个 AND 按钮,按下该按钮会将所有大写的AND"添加到文本字段中,并用空格包围.这可以做到吗?
  4. 要问的是如何在 onKeyPress 事件中捕获一些组合键,然后用模式填充文本字段 - 我已经知道如何做到这一点了.
解决方案

它由 android:inputType XML 属性(或 setInputType() 方法)控制.

有关可用选项的信息,请参阅 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:

  1. how to trigger this customization? I suspect it has to do with EditText format
  2. 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?
  3. 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.

这篇关于Android - 自定义键盘按键和操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 22:09