Key
open classKey
kotlin.Any | |
↳ | android.inputmethodservice.Keyboard.Key |
Class for describing the position and characteristics of a single key in the keyboard.
Summary
XML attributes | |
---|---|
android:codes |
The unicode value or comma-separated values that this key outputs. |
android:horizontalGap |
Default horizontal gap between keys. |
android:iconPreview |
The icon to show in the popup preview. |
android:isModifier |
Whether this is a modifier key such as Alt or Shift. |
android:isRepeatable |
Whether long-pressing on this key will make it repeat. |
android:isSticky |
Whether this is a toggle key. |
android:keyEdgeFlags |
Key edge flags. |
android:keyHeight |
Default height of a key, in pixels or percentage of display width. |
android:keyIcon |
The icon to display on the key instead of the label. |
android:keyLabel |
The label to display on the key. |
android:keyOutputText |
The string of characters to output when this key is pressed. |
android:keyWidth |
Default width of a key, in pixels or percentage of display width. |
android:popupCharacters |
The characters to display in the popup keyboard. |
android:popupKeyboard |
The XML keyboard layout of any popup keyboard. |
Public constructors | |
---|---|
Key(parent: Keyboard.Row!) Create an empty key with no attributes. |
|
Key(res: Resources!, parent: Keyboard.Row!, x: Int, y: Int, parser: XmlResourceParser!) Create a key with the given top-left coordinate and extract its attributes from the XML parser. |
Public methods | |
---|---|
open IntArray! |
Returns the drawable state for the key, based on the current state and type of the key. |
open Boolean |
Detects if a point falls inside this key. |
open Unit |
Informs the key that it has been pressed, in case it needs to change its appearance or state. |
open Unit |
onReleased(inside: Boolean) Changes the pressed state of the key. |
open Int |
squaredDistanceFrom(x: Int, y: Int) Returns the square of the distance between the center of the key and the given point. |
Properties | |
---|---|
IntArray! |
All the key codes (unicode or custom code) that this key could generate, zero'th being the most important. |
Int |
Flags that specify the anchoring to edges of the keyboard for detecting touch events that are just out of the boundary of the key. |
Int |
The horizontal gap before this key |
Int |
Height of the key, not including the gap |
Drawable! |
Icon to display instead of a label. |
Drawable! |
Preview version of the icon, for the preview popup |
CharSequence! |
Label to display |
Boolean |
Whether this is a modifier key, such as Shift or Alt |
Boolean |
If this is a sticky key, is it on? |
CharSequence! |
Popup characters |
Int |
If this key pops up a mini keyboard, this is the resource id for the XML layout for that keyboard. |
Boolean |
The current pressed state of this key |
Boolean |
Whether this key repeats itself when held down |
Boolean |
Whether this key is sticky, i. |
CharSequence! |
Text to output when pressed. |
Int |
Width of the key, not including the gap |
Int |
X coordinate of the key in the keyboard layout |
Int |
Y coordinate of the key in the keyboard layout |
XML attributes
android:codes
android:codes
May be a string value, using '\\;' to escape characters such as '\\n' or '\\uxxxx' for a unicode character;
May be an integer value, such as "100
".
android:horizontalGap
android:horizontalGap
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:iconPreview
android:iconPreview
May be a reference to another resource, in the form "@[+][package:]type/name
" or a theme attribute in the form "?[package:]type/name
".
android:isModifier
android:isModifier
May be a boolean value, such as "true
" or "false
".
android:isRepeatable
android:isRepeatable
May be a boolean value, such as "true
" or "false
".
android:isSticky
android:isSticky
May be a boolean value, such as "true
" or "false
".
android:keyEdgeFlags
android:keyEdgeFlags
Must be one or more (separated by '|') of the following constant values.
Constant | Value | Description |
---|---|---|
left | 1 | Key is anchored to the left of the keyboard. {@deprecated Copy this definition into your own application project.} |
right | 2 | Key is anchored to the right of the keyboard. {@deprecated Copy this definition into your own application project.} |
android:keyHeight
android:keyHeight
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:keyIcon
android:keyIcon
May be a reference to another resource, in the form "@[+][package:]type/name
" or a theme attribute in the form "?[package:]type/name
".
android:keyLabel
android:keyLabel
May be a string value, using '\\;' to escape characters such as '\\n' or '\\uxxxx' for a unicode character;
android:keyOutputText
android:keyOutputText
May be a string value, using '\\;' to escape characters such as '\\n' or '\\uxxxx' for a unicode character;
android:keyWidth
android:keyWidth
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:popupCharacters
android:popupCharacters
May be a string value, using '\\;' to escape characters such as '\\n' or '\\uxxxx' for a unicode character;
android:popupKeyboard
android:popupKeyboard
May be a reference to another resource, in the form "@[+][package:]type/name
" or a theme attribute in the form "?[package:]type/name
".
Public constructors
Key
Key(
res: Resources!,
parent: Keyboard.Row!,
x: Int,
y: Int,
parser: XmlResourceParser!)
Create a key with the given top-left coordinate and extract its attributes from the XML parser.
Parameters | |
---|---|
res |
Resources!: resources associated with the caller's context |
parent |
Keyboard.Row!: the row that this key belongs to. The row must already be attached to a Keyboard . |
x |
Int: the x coordinate of the top-left |
y |
Int: the y coordinate of the top-left |
parser |
XmlResourceParser!: the XML parser containing the attributes for this key |
Public methods
getCurrentDrawableState
open fungetCurrentDrawableState(): IntArray!
Deprecated: Deprecated in Java.
Returns the drawable state for the key, based on the current state and type of the key.
Return | |
---|---|
IntArray! |
the drawable state of the key. |
isInside
open funisInside(
x: Int,
y: Int
): Boolean
Deprecated: Deprecated in Java.
Detects if a point falls inside this key.
Parameters | |
---|---|
x |
Int: the x-coordinate of the point |
y |
Int: the y-coordinate of the point |
Return | |
---|---|
Boolean |
whether or not the point falls inside the key. If the key is attached to an edge, it will assume that all points between the key and the edge are considered to be inside the key. |
onPressed
open funonPressed(): Unit
Deprecated: Deprecated in Java.
Informs the key that it has been pressed, in case it needs to change its appearance or state.
See Also
onReleased
open funonReleased(inside: Boolean): Unit
Deprecated: Deprecated in Java.
Changes the pressed state of the key.
Toggled state of the key will be flipped when all the following conditions are fulfilled:
- This is a sticky key, that is,
sticky
istrue
. - The parameter
inside
istrue
. android.os.Build.VERSION#SDK_INT
is greater thanandroid.os.Build.VERSION_CODES#LOLLIPOP_MR1
.
Parameters | |
---|---|
inside |
Boolean: whether the finger was released inside the key. Works only on Android M and later. See the method document for details. |
See Also
squaredDistanceFrom
open funsquaredDistanceFrom(
x: Int,
y: Int
): Int
Deprecated: Deprecated in Java.
Returns the square of the distance between the center of the key and the given point.
Parameters | |
---|---|
x |
Int: the x-coordinate of the point |
y |
Int: the y-coordinate of the point |
Return | |
---|---|
Int |
the square of the distance of the point from the center of the key |
Properties
codes
varcodes: IntArray!
Deprecated: Deprecated in Java.
All the key codes (unicode or custom code) that this key could generate, zero'th being the most important.
edgeFlags
varedgeFlags: Int
Deprecated: Deprecated in Java.
Flags that specify the anchoring to edges of the keyboard for detecting touch events that are just out of the boundary of the key. This is a bit mask of Keyboard#EDGE_LEFT
, Keyboard#EDGE_RIGHT
, Keyboard#EDGE_TOP
and Keyboard#EDGE_BOTTOM
.
gap
vargap: Int
Deprecated: Deprecated in Java.
The horizontal gap before this key
height
varheight: Int
Deprecated: Deprecated in Java.
Height of the key, not including the gap
icon
varicon: Drawable!
Deprecated: Deprecated in Java.
Icon to display instead of a label. Icon takes precedence over a label
iconPreview
variconPreview: Drawable!
Deprecated: Deprecated in Java.
Preview version of the icon, for the preview popup
label
varlabel: CharSequence!
Deprecated: Deprecated in Java.
Label to display
modifier
varmodifier: Boolean
Deprecated: Deprecated in Java.
Whether this is a modifier key, such as Shift or Alt
on
varon: Boolean
Deprecated: Deprecated in Java.
If this is a sticky key, is it on?
popupCharacters
varpopupCharacters: CharSequence!
Deprecated: Deprecated in Java.
Popup characters
popupResId
varpopupResId: Int
Deprecated: Deprecated in Java.
If this key pops up a mini keyboard, this is the resource id for the XML layout for that keyboard.
pressed
varpressed: Boolean
Deprecated: Deprecated in Java.
The current pressed state of this key
repeatable
varrepeatable: Boolean
Deprecated: Deprecated in Java.
Whether this key repeats itself when held down
sticky
varsticky: Boolean
Deprecated: Deprecated in Java.
Whether this key is sticky, i.e., a toggle key
text
vartext: CharSequence!
Deprecated: Deprecated in Java.
Text to output when pressed. This can be multiple characters, like ".com"
width
varwidth: Int
Deprecated: Deprecated in Java.
Width of the key, not including the gap
x
varx: Int
Deprecated: Deprecated in Java.
X coordinate of the key in the keyboard layout
y
vary: Int
Deprecated: Deprecated in Java.
Y coordinate of the key in the keyboard layout