public class

Keyboard

extends Object
java.lang.Object
   ↳android.inputmethodservice.Keyboard

Class Overview

Loads an XML description of a keyboard and stores the attributes of the keys. A keyboard consists of rows of keys.

The layout file for a keyboard contains XML that looks like the following snippet:

 <Keyboard
         android:keyWidth="%10p"
         android:keyHeight="50px"
         android:horizontalGap="2px"
         android:verticalGap="2px" >
     <Row android:keyWidth="32px" >
         <Key android:keyLabel="A" />
         ...
     </Row>
     ...
 </Keyboard>
 

Summary

Nested Classes
classKeyboard.KeyClass for describing the position and characteristics of a single key in the keyboard. 
classKeyboard.RowContainer for keys in the keyboard. 
XML Attributes
Attribute NameRelated MethodDescription
android:horizontalGap Default horizontal gap between keys. 
android:keyHeight Default height of a key, in pixels or percentage of display width. 
android:keyWidth Default width of a key, in pixels or percentage of display width. 
android:verticalGap Default vertical gap between rows of keys. 
Constants
intEDGE_BOTTOM
intEDGE_LEFT
intEDGE_RIGHT
intEDGE_TOP
intKEYCODE_ALT
intKEYCODE_CANCEL
intKEYCODE_DELETE
intKEYCODE_DONE
intKEYCODE_MODE_CHANGE
intKEYCODE_SHIFT
Public Constructors
Keyboard(Context context, int xmlLayoutResId)
Creates a keyboard from the given xml key layout file.
Keyboard(Context context, int xmlLayoutResId, int modeId)
Creates a keyboard from the given xml key layout file.
Keyboard(Context context, int layoutTemplateResId, CharSequence characters, int columns, int horizontalPadding)

Creates a blank keyboard from the given resource file and populates it with the specified characters in left-to-right, top-to-bottom fashion, using the specified number of columns.

Public Methods
int getHeight()
Returns the total height of the keyboard
List<Keyboard.Key> getKeys()
int getMinWidth()
List<Keyboard.Key> getModifierKeys()
int[] getNearestKeys(int x, int y)
Returns the indices of the keys that are closest to the given point.
int getShiftKeyIndex()
boolean isShifted()
boolean setShifted(boolean shiftState)
Protected Methods
Keyboard.Key createKeyFromXml(Resources res, Keyboard.Row parent, int x, int y, XmlResourceParser parser)
Keyboard.Row createRowFromXml(Resources res, XmlResourceParser parser)
int getHorizontalGap()
int getKeyHeight()
int getKeyWidth()
int getVerticalGap()
void setHorizontalGap(int gap)
void setKeyHeight(int height)
void setKeyWidth(int width)
void setVerticalGap(int gap)
[Expand]
Inherited Methods
From class java.lang.Object

XML Attributes

android:horizontalGap

Since: API Level

Default horizontal gap between keys.

May be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), mm (millimeters).

May be a fractional value, which is a floating point number appended with either % or %p, such as "14.5%". The % suffix always means a percentage of the base size; the optional %p suffix provides a size relative to some parent container.

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol horizontalGap.

Related Methods

    android:keyHeight

    Since: API Level

    Default height of a key, in pixels or percentage of display width.

    May be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), mm (millimeters).

    May be a fractional value, which is a floating point number appended with either % or %p, such as "14.5%". The % suffix always means a percentage of the base size; the optional %p suffix provides a size relative to some parent container.

    This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

    This corresponds to the global attribute resource symbol keyHeight.

    Related Methods

      android:keyWidth

      Since: API Level

      Default width of a key, in pixels or percentage of display width.

      May be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), mm (millimeters).

      May be a fractional value, which is a floating point number appended with either % or %p, such as "14.5%". The % suffix always means a percentage of the base size; the optional %p suffix provides a size relative to some parent container.

      This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

      This corresponds to the global attribute resource symbol keyWidth.

      Related Methods

        android:verticalGap

        Since: API Level

        Default vertical gap between rows of keys.

        May be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), mm (millimeters).

        May be a fractional value, which is a floating point number appended with either % or %p, such as "14.5%". The % suffix always means a percentage of the base size; the optional %p suffix provides a size relative to some parent container.

        This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

        This corresponds to the global attribute resource symbol verticalGap.

        Related Methods

          Constants

          public static final int EDGE_BOTTOM

          Since: API Level 3

          Constant Value: 8 (0x00000008)

          public static final int EDGE_LEFT

          Since: API Level 3

          Constant Value: 1 (0x00000001)

          public static final int EDGE_RIGHT

          Since: API Level 3

          Constant Value: 2 (0x00000002)

          public static final int EDGE_TOP

          Since: API Level 3

          Constant Value: 4 (0x00000004)

          public static final int KEYCODE_ALT

          Since: API Level 3

          Constant Value: -6 (0xfffffffa)

          public static final int KEYCODE_CANCEL

          Since: API Level 3

          Constant Value: -3 (0xfffffffd)

          public static final int KEYCODE_DELETE

          Since: API Level 3

          Constant Value: -5 (0xfffffffb)

          public static final int KEYCODE_DONE

          Since: API Level 3

          Constant Value: -4 (0xfffffffc)

          public static final int KEYCODE_MODE_CHANGE

          Since: API Level 3

          Constant Value: -2 (0xfffffffe)

          public static final int KEYCODE_SHIFT

          Since: API Level 3

          Constant Value: -1 (0xffffffff)

          Public Constructors

          public Keyboard (Context context, int xmlLayoutResId)

          Since: API Level 3

          Creates a keyboard from the given xml key layout file.

          Parameters
          context the application or service context
          xmlLayoutResId the resource file that contains the keyboard layout and keys.

          public Keyboard (Context context, int xmlLayoutResId, int modeId)

          Since: API Level 3

          Creates a keyboard from the given xml key layout file. Weeds out rows that have a keyboard mode defined but don't match the specified mode.

          Parameters
          context the application or service context
          xmlLayoutResId the resource file that contains the keyboard layout and keys.
          modeId keyboard mode identifier

          public Keyboard (Context context, int layoutTemplateResId, CharSequence characters, int columns, int horizontalPadding)

          Since: API Level 3

          Creates a blank keyboard from the given resource file and populates it with the specified characters in left-to-right, top-to-bottom fashion, using the specified number of columns.

          If the specified number of columns is -1, then the keyboard will fit as many keys as possible in each row.

          Parameters
          context the application or service context
          layoutTemplateResId the layout template file, containing no keys.
          characters the list of characters to display on the keyboard. One key will be created for each character.
          columns the number of columns of keys to display. If this number is greater than the number of keys that can fit in a row, it will be ignored. If this number is -1, the keyboard will fit as many keys as possible in each row.

          Public Methods

          public int getHeight ()

          Since: API Level 3

          Returns the total height of the keyboard

          Returns
          • the total height of the keyboard

          public List<Keyboard.Key> getKeys ()

          Since: API Level 3

          public int getMinWidth ()

          Since: API Level 3

          public List<Keyboard.Key> getModifierKeys ()

          Since: API Level 3

          public int[] getNearestKeys (int x, int y)

          Since: API Level 3

          Returns the indices of the keys that are closest to the given point.

          Parameters
          x the x-coordinate of the point
          y the y-coordinate of the point
          Returns
          • the array of integer indices for the nearest keys to the given point. If the given point is out of range, then an array of size zero is returned.

          public int getShiftKeyIndex ()

          Since: API Level 3

          public boolean isShifted ()

          Since: API Level 3

          public boolean setShifted (boolean shiftState)

          Since: API Level 3

          Protected Methods

          protected Keyboard.Key createKeyFromXml (Resources res, Keyboard.Row parent, int x, int y, XmlResourceParser parser)

          Since: API Level 3

          protected Keyboard.Row createRowFromXml (Resources res, XmlResourceParser parser)

          Since: API Level 3

          protected int getHorizontalGap ()

          Since: API Level 3

          protected int getKeyHeight ()

          Since: API Level 3

          protected int getKeyWidth ()

          Since: API Level 3

          protected int getVerticalGap ()

          Since: API Level 3

          protected void setHorizontalGap (int gap)

          Since: API Level 3

          protected void setKeyHeight (int height)

          Since: API Level 3

          protected void setKeyWidth (int width)

          Since: API Level 3

          protected void setVerticalGap (int gap)

          Since: API Level 3