Added in API level 3
Deprecated in API level 29

KeyboardView


open class KeyboardView : View, View.OnClickListener
kotlin.Any
   ↳ android.view.View
   ↳ android.inputmethodservice.KeyboardView

A view that renders a virtual Keyboard. It handles rendering of keys and detecting key presses and touch movements.

Summary

Nested classes
abstract

Listener for virtual keyboard events.

XML attributes
android:keyBackground Image for the key.
android:keyPreviewHeight Height of the key press feedback popup.
android:keyPreviewLayout Layout resource for key press feedback.
android:keyPreviewOffset Vertical offset of the key press feedback from the key.
android:keyTextColor Color to use for the label in a key.
android:keyTextSize Size of the text for character keys.
android:labelTextSize Size of the text for custom keys with some text and no icon.
android:popupLayout Layout resource for popup keyboards.
android:verticalCorrection Amount to offset the touch Y coordinate by, for bias correction.
Inherited XML attributes
Inherited constants
Public constructors
KeyboardView(context: Context!, attrs: AttributeSet!)

KeyboardView(context: Context!, attrs: AttributeSet!, defStyleAttr: Int)

KeyboardView(context: Context!, attrs: AttributeSet!, defStyleAttr: Int, defStyleRes: Int)

Public methods
open Unit

open Keyboard!

Returns the current keyboard being displayed by this view.

open Boolean

open Unit

Requests a redraw of the entire keyboard.

open Unit
invalidateKey(keyIndex: Int)

Invalidates a key so that it will be redrawn on the next repaint.

open Boolean

Returns the enabled state of the key feedback popup.

open Boolean

Returns true if proximity correction is enabled.

open Boolean

Returns the state of the shift key of the keyboard, if any.

open Unit

open Unit
onDraw(canvas: Canvas)

open Boolean

open Unit
onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int)

open Unit
onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int)

open Boolean

open Unit
setKeyboard(keyboard: Keyboard!)

Attaches a keyboard to this view.

open Unit

open Unit

open Unit

open Unit
setPreviewEnabled(previewEnabled: Boolean)

Enables or disables the key feedback popup.

open Unit

When enabled, calls to OnKeyboardActionListener#onKey will include key codes for adjacent keys.

open Boolean
setShifted(shifted: Boolean)

Sets the state of the shift key of the keyboard, if any.

open Unit
setVerticalCorrection(verticalOffset: Int)

Protected methods
open KeyboardView.OnKeyboardActionListener!

Returns the OnKeyboardActionListener object.

open Unit

open Boolean

Called when a key is long pressed.

open Unit

open Unit

open Unit

open Unit

Inherited functions
Inherited properties

XML attributes

android:keyBackground

android:keyBackground
Image for the key. This image needs to be a StateListDrawable, with the following possible states: normal, pressed, checkable, checkable+pressed, checkable+checked, checkable+checked+pressed. {@deprecated Copy this definition into your own application project.}

May be a reference to another resource, in the form "@[+][package:]type/name" or a theme attribute in the form "?[package:]type/name".

android:keyPreviewHeight

android:keyPreviewHeight
Height of the key press feedback popup. {@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).

android:keyPreviewLayout

android:keyPreviewLayout
Layout resource for key press feedback. {@deprecated Copy this definition into your own application project.}

May be a reference to another resource, in the form "@[+][package:]type/name" or a theme attribute in the form "?[package:]type/name".

android:keyPreviewOffset

android:keyPreviewOffset
Vertical offset of the key press feedback from the key. {@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).

android:keyTextColor

android:keyTextColor
Color to use for the label in a key. {@deprecated Copy this definition into your own application project.}

May be a color value, in the form of "rgb", "argb", "rrggbb", or "aarrggbb".

android:keyTextSize

android:keyTextSize
Size of the text for character 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).

android:labelTextSize

android:labelTextSize
Size of the text for custom keys with some text and no icon. {@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).

android:popupLayout

android:popupLayout
Layout resource for popup keyboards. {@deprecated Copy this definition into your own application project.}

May be a reference to another resource, in the form "@[+][package:]type/name" or a theme attribute in the form "?[package:]type/name".

android:verticalCorrection

android:verticalCorrection
Amount to offset the touch Y coordinate by, for bias correction. {@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).

Public constructors

KeyboardView

Added in API level 3
KeyboardView(
    context: Context!,
    attrs: AttributeSet!)

KeyboardView

Added in API level 3
KeyboardView(
    context: Context!,
    attrs: AttributeSet!,
    defStyleAttr: Int)

KeyboardView

Added in API level 21
KeyboardView(
    context: Context!,
    attrs: AttributeSet!,
    defStyleAttr: Int,
    defStyleRes: Int)

Public methods

closing

Added in API level 3
open fun closing(): Unit

Deprecated: Deprecated in Java.

getKeyboard

Added in API level 3
open fun getKeyboard(): Keyboard!

Deprecated: Deprecated in Java.

Returns the current keyboard being displayed by this view.

Return
Keyboard! the currently attached keyboard

handleBack

Added in API level 3
open fun handleBack(): Boolean

Deprecated: Deprecated in Java.

invalidateAllKeys

Added in API level 4
Deprecated in API level 29
open fun invalidateAllKeys(): Unit

Deprecated: Deprecated in Java.

Requests a redraw of the entire keyboard. Calling #invalidate is not sufficient because the keyboard renders the keys to an off-screen buffer and an invalidate() only draws the cached buffer.

invalidateKey

Added in API level 4
Deprecated in API level 29
open fun invalidateKey(keyIndex: Int): Unit

Deprecated: Deprecated in Java.

Invalidates a key so that it will be redrawn on the next repaint. Use this method if only one key is changing it's content. Any changes that affect the position or size of the key may not be honored.

Parameters
keyIndex Int: the index of the key in the attached Keyboard.

isPreviewEnabled

Added in API level 3
open fun isPreviewEnabled(): Boolean

Deprecated: Deprecated in Java.

Returns the enabled state of the key feedback popup.

Return
Boolean whether or not the key feedback popup is enabled

isProximityCorrectionEnabled

Added in API level 3
open fun isProximityCorrectionEnabled(): Boolean

Deprecated: Deprecated in Java.

Returns true if proximity correction is enabled.

isShifted

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

Deprecated: Deprecated in Java.

Returns the state of the shift key of the keyboard, if any.

Return
Boolean true if the shift is in a pressed state, false otherwise. If there is no shift key on the keyboard or there is no keyboard attached, it returns false.

onDetachedFromWindow

Added in API level 3
open fun onDetachedFromWindow(): Unit

Deprecated: Deprecated in Java.

onDraw

Added in API level 3
open fun onDraw(canvas: Canvas): Unit

Deprecated: Deprecated in Java.

Parameters
canvas Canvas: the canvas on which the background will be drawn This value cannot be null.

onHoverEvent

Added in API level 14
Deprecated in API level 29
open fun onHoverEvent(event: MotionEvent!): Boolean

Deprecated: Deprecated in Java.

Parameters
event MotionEvent!: The motion event that describes the hover.
Return
Boolean True if the view handled the hover event.

onMeasure

Added in API level 3
open fun onMeasure(
    widthMeasureSpec: Int,
    heightMeasureSpec: Int
): Unit

Deprecated: Deprecated in Java.

Parameters
widthMeasureSpec Int: horizontal space requirements as imposed by the parent. The requirements are encoded with android.view.View.MeasureSpec.
heightMeasureSpec Int: vertical space requirements as imposed by the parent. The requirements are encoded with android.view.View.MeasureSpec.

onSizeChanged

Added in API level 3
open fun onSizeChanged(
    w: Int,
    h: Int,
    oldw: Int,
    oldh: Int
): Unit

Deprecated: Deprecated in Java.

Parameters
w Int: Current width of this view.
h Int: Current height of this view.
oldw Int: Old width of this view.
oldh Int: Old height of this view.

onTouchEvent

Added in API level 3
open fun onTouchEvent(me: MotionEvent!): Boolean

Deprecated: Deprecated in Java.

Parameters
event The motion event.
Return
Boolean True if the event was handled, false otherwise.

setKeyboard

Added in API level 3
open fun setKeyboard(keyboard: Keyboard!): Unit

Deprecated: Deprecated in Java.

Attaches a keyboard to this view. The keyboard can be switched at any time and the view will re-layout itself to accommodate the keyboard.

Parameters
keyboard Keyboard!: the keyboard to display in this view

setOnKeyboardActionListener

Added in API level 3
open fun setOnKeyboardActionListener(listener: KeyboardView.OnKeyboardActionListener!): Unit

Deprecated: Deprecated in Java.

setPopupOffset

Added in API level 3
open fun setPopupOffset(
    x: Int,
    y: Int
): Unit

Deprecated: Deprecated in Java.

setPopupParent

Added in API level 3
open fun setPopupParent(v: View!): Unit

Deprecated: Deprecated in Java.

setPreviewEnabled

Added in API level 3
open fun setPreviewEnabled(previewEnabled: Boolean): Unit

Deprecated: Deprecated in Java.

Enables or disables the key feedback popup. This is a popup that shows a magnified version of the depressed key. By default the preview is enabled.

Parameters
previewEnabled Boolean: whether or not to enable the key feedback popup

setProximityCorrectionEnabled

Added in API level 3
open fun setProximityCorrectionEnabled(enabled: Boolean): Unit

Deprecated: Deprecated in Java.

When enabled, calls to OnKeyboardActionListener#onKey will include key codes for adjacent keys. When disabled, only the primary key code will be reported.

Parameters
enabled Boolean: whether or not the proximity correction is enabled

setShifted

Added in API level 3
open fun setShifted(shifted: Boolean): Boolean

Deprecated: Deprecated in Java.

Sets the state of the shift key of the keyboard, if any.

Parameters
shifted Boolean: whether or not to enable the state of the shift key
Return
Boolean true if the shift key state changed, false if there was no change

setVerticalCorrection

Added in API level 3
open fun setVerticalCorrection(verticalOffset: Int): Unit

Deprecated: Deprecated in Java.

Protected methods

getOnKeyboardActionListener

Added in API level 3
protected open fun getOnKeyboardActionListener(): KeyboardView.OnKeyboardActionListener!

Deprecated: Deprecated in Java.

Returns the OnKeyboardActionListener object.

Return
KeyboardView.OnKeyboardActionListener! the listener attached to this keyboard

onAttachedToWindow

Added in API level 3
protected open fun onAttachedToWindow(): Unit

Deprecated: Deprecated in Java.

onLongPress

Added in API level 3
protected open fun onLongPress(popupKey: Keyboard.Key!): Boolean

Deprecated: Deprecated in Java.

Called when a key is long pressed. By default this will open any popup keyboard associated with this key through the attributes popupLayout and popupCharacters.

Parameters
popupKey Keyboard.Key!: the key that was long pressed
Return
Boolean true if the long press is handled, false otherwise. Subclasses should call the method on the base class if the subclass doesn't wish to handle the call.

swipeDown

Added in API level 3
protected open fun swipeDown(): Unit

Deprecated: Deprecated in Java.

swipeLeft

Added in API level 3
protected open fun swipeLeft(): Unit

Deprecated: Deprecated in Java.

swipeRight

Added in API level 3
protected open fun swipeRight(): Unit

Deprecated: Deprecated in Java.

swipeUp

Added in API level 3
protected open fun swipeUp(): Unit

Deprecated: Deprecated in Java.