Android的 - cutomized键盘按键和行动 [英] Android - cutomized keyboard key and action

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

问题描述

如果你拥有Android手机的你无疑已经注意到如何在特定的应用程序的键盘布局可以从标准问题,更改为数字或只具有 .COM 基于文本字段中输入类型(如电话号码)或 .NET 特殊按钮。所以,我有2个问题:

  1. 如何触发这个定制?我怀疑它必须与的EditText 格式
  2. 在这个问题能更进一步,如果我想添加一些自定义按钮注入特定的模式拍摄?说我将有一个按钮,当pressed将增加所有大写和按空格包围文本字段。可以这样做?
  3. 在什么我的没有的要价是如何捕获onKey preSS事件的一些组合键,然后填充文本字段的模式 - 我pretty的多少知道该怎么做已经
解决方案

这是由 Android的控制:inputType XML属性(或 setInputType ()法)。

有关可用选项的信息看页面的<一个href="http://developer.android.com/reference/android/widget/TextView.html#attr%5Fandroid%3AinputType">XML属性或对象的方法

作为一个例子,下面的XML:

 &LT; XML版本=1.0编码=UTF-8&GT?;
&LT; LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:方向=垂直
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT&GT;
    &LT;的EditText
    机器人:文本=示例文本
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:inputType =手机/&GT;
&LT; / LinearLayout中&GT;
 

会给你这样的布局:

而更改 inputType textEmailAddress 会给你这样的:

您可以作为解释自定义操作按钮<一个href="http://stackoverflow.com/questions/1538331/android-cant-figure-how-to-use-setimeactionlabel#1541161">here,但我不相信有什么办法可以做到的键盘完全自定义,在这个时候,但我可能是错的。

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的 - cutomized键盘按键和行动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆