Google is committed to advancing racial equity for Black communities. See how.
Added in API level 3
Deprecated in API level 29

Keyboard

open class Keyboard
kotlin.Any
   ↳ android.inputmethodservice.Keyboard

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
open

Class for describing the position and characteristics of a single key in the keyboard.

open

Container for keys in the keyboard.

XML attributes
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
static Int

static Int

static Int

static Int

static Int

static Int

static Int

static Int

static Int

static Int

Public constructors
<init>(context: Context!, xmlLayoutResId: Int)

Creates a keyboard from the given xml key layout file.

<init>(context: Context!, xmlLayoutResId: Int, modeId: Int, width: Int, height: Int)

Creates a keyboard from the given xml key layout file.

<init>(context: Context!, xmlLayoutResId: Int, modeId: Int)

Creates a keyboard from the given xml key layout file.

<init>(context: Context!, layoutTemplateResId: Int, characters: CharSequence!, columns: Int, horizontalPadding: Int)

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
open Int

Returns the total height of the keyboard

open MutableList<Keyboard.Key!>!

open Int

open MutableList<Keyboard.Key!>!

open IntArray!

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

open Int

open Boolean

open Boolean
setShifted(shiftState: Boolean)

Protected methods
open Keyboard.Key!
createKeyFromXml(res: Resources!, parent: Keyboard.Row!, x: Int, y: Int, parser: XmlResourceParser!)

open Keyboard.Row!

open Int

open Int

open Int

open Int

open Unit

open Unit
setKeyHeight(height: Int)

open Unit
setKeyWidth(width: Int)

open Unit

XML attributes

android:horizontalGap

android:horizontalGap
Default horizontal gap between keys. {@deprecated Copy this definition into your own application project.}

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), and 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.

android:keyHeight

android:keyHeight
Default height of a key, in pixels or percentage of display width. {@deprecated Copy this definition into your own application project.}

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), and 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.

android:keyWidth

android:keyWidth
Default width of a key, in pixels or percentage of display width. {@deprecated Copy this definition into your own application project.}

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), and 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.

android:verticalGap

android:verticalGap
Default vertical gap between rows of keys. {@deprecated Copy this definition into your own application project.}

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), and 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.

Constants

EDGE_BOTTOM

Added in API level 3
Deprecated in API level 29
static val EDGE_BOTTOM: Int

Deprecated.

Value: 8

EDGE_LEFT

Added in API level 3
Deprecated in API level 29
static val EDGE_LEFT: Int

Deprecated.

Value: 1

EDGE_RIGHT

Added in API level 3
Deprecated in API level 29
static val EDGE_RIGHT: Int

Deprecated.

Value: 2

EDGE_TOP

Added in API level 3
Deprecated in API level 29
static val EDGE_TOP: Int

Deprecated.

Value: 4

KEYCODE_ALT

Added in API level 3
Deprecated in API level 29
static val KEYCODE_ALT: Int

Deprecated.

Value: -6

KEYCODE_CANCEL

Added in API level 3
Deprecated in API level 29
static val KEYCODE_CANCEL: Int

Deprecated.

Value: -3

KEYCODE_DELETE

Added in API level 3
Deprecated in API level 29
static val KEYCODE_DELETE: Int

Deprecated.

Value: -5

KEYCODE_DONE

Added in API level 3
Deprecated in API level 29
static val KEYCODE_DONE: Int

Deprecated.

Value: -4

KEYCODE_MODE_CHANGE

Added in API level 3
Deprecated in API level 29
static val KEYCODE_MODE_CHANGE: Int

Deprecated.

Value: -2

KEYCODE_SHIFT

Added in API level 3
Deprecated in API level 29
static val KEYCODE_SHIFT: Int

Deprecated.

Value: -1

Public constructors

<init>

Added in API level 3
Keyboard(
    context: Context!,
    xmlLayoutResId: Int)

Creates a keyboard from the given xml key layout file.

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

<init>

Added in API level 11
Keyboard(
    context: Context!,
    xmlLayoutResId: Int,
    modeId: Int,
    width: Int,
    height: Int)

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 Context!: the application or service context
xmlLayoutResId Int: the resource file that contains the keyboard layout and keys.
modeId Int: keyboard mode identifier
width Int: sets width of keyboard
height Int: sets height of keyboard

<init>

Added in API level 3
Keyboard(
    context: Context!,
    xmlLayoutResId: Int,
    modeId: Int)

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 Context!: the application or service context
xmlLayoutResId Int: the resource file that contains the keyboard layout and keys.
modeId Int: keyboard mode identifier

<init>

Added in API level 3
Keyboard(
    context: Context!,
    layoutTemplateResId: Int,
    characters: CharSequence!,
    columns: Int,
    horizontalPadding: Int)

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 Context!: the application or service context
layoutTemplateResId Int: the layout template file, containing no keys.
characters CharSequence!: the list of characters to display on the keyboard. One key will be created for each character.
columns Int: 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

getHeight

Added in API level 3
Deprecated in API level 29
open fun getHeight(): Int

Deprecated.

Returns the total height of the keyboard

Return
Int the total height of the keyboard

getKeys

Added in API level 3
Deprecated in API level 29
open fun getKeys(): MutableList<Keyboard.Key!>!

Deprecated.

getMinWidth

Added in API level 3
Deprecated in API level 29
open fun getMinWidth(): Int

Deprecated.

getModifierKeys

Added in API level 3
Deprecated in API level 29
open fun getModifierKeys(): MutableList<Keyboard.Key!>!

Deprecated.

getNearestKeys

Added in API level 3
Deprecated in API level 29
open fun getNearestKeys(
    x: Int,
    y: Int
): IntArray!

Deprecated.

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

Parameters
x Int: the x-coordinate of the point
y Int: the y-coordinate of the point
Return
IntArray! 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.

getShiftKeyIndex

Added in API level 3
Deprecated in API level 29
open fun getShiftKeyIndex(): Int

Deprecated.

isShifted

Added in API level 3
Deprecated in API level 29
open fun isShifted(): Boolean

Deprecated.

setShifted

Added in API level 3
Deprecated in API level 29
open fun setShifted(shiftState: Boolean): Boolean

Deprecated.

Protected methods

createKeyFromXml

Added in API level 3
Deprecated in API level 29
protected open fun createKeyFromXml(
    res: Resources!,
    parent: Keyboard.Row!,
    x: Int,
    y: Int,
    parser: XmlResourceParser!
): Keyboard.Key!

Deprecated.

createRowFromXml

Added in API level 3
Deprecated in API level 29
protected open fun createRowFromXml(
    res: Resources!,
    parser: XmlResourceParser!
): Keyboard.Row!

Deprecated.

getHorizontalGap

Added in API level 3
Deprecated in API level 29
protected open fun getHorizontalGap(): Int

Deprecated.

getKeyHeight

Added in API level 3
Deprecated in API level 29
protected open fun getKeyHeight(): Int

Deprecated.

getKeyWidth

Added in API level 3
Deprecated in API level 29
protected open fun getKeyWidth(): Int

Deprecated.

getVerticalGap

Added in API level 3
Deprecated in API level 29
protected open fun getVerticalGap(): Int

Deprecated.

setHorizontalGap

Added in API level 3
Deprecated in API level 29
protected open fun setHorizontalGap(gap: Int): Unit

Deprecated.

setKeyHeight

Added in API level 3
Deprecated in API level 29
protected open fun setKeyHeight(height: Int): Unit

Deprecated.

setKeyWidth

Added in API level 3
Deprecated in API level 29
protected open fun setKeyWidth(width: Int): Unit

Deprecated.

setVerticalGap

Added in API level 3
Deprecated in API level 29
protected open fun setVerticalGap(gap: Int): Unit

Deprecated.