Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - customized keyboard key and action

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.
like image 939
Bostone Avatar asked Nov 03 '09 22:11

Bostone


2 Answers

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:

Hosted by imgur.com

whereas changing the inputType to textEmailAddress will give you this:

Hosted by imgur.com

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.

like image 59
Jeremy Logan Avatar answered Oct 29 '22 21:10

Jeremy Logan


The thing that concerns me is that "inputType" is listed as a deprecated property, meaning it may work for a while, but - eventually - Android will stop supporting it. Is there another alternative?

UPDATED: My bad - I'm confusing with inputMethod.

like image 36
Chas Avatar answered Oct 29 '22 21:10

Chas