Keyboard
Keyboardで、キーボードのキー配置を定義できます。
レイアウト ファイルの定義
キーの配置はXMLで定義します。そしてこれをリソースとしてres/xml/ディレクトリに配置します。
定義例
<Keyboard xmlns:android="http://schemas.android.com/apk/res/android"
android:keyWidth="10%p"
android:keyHeight="50px"
android:horizontalGap="2px"
android:verticalGap="2px"
>
<Row android:keyWidth="32px">
<Key android:keyLabel="A" />
</Row>
</Keyboard>
- Keyboard.Rowクラス … キーボードのキー (Keyクラス) のコンテナ
- Keyboard.Keyクラス … キーボードのひとつのキーの定義
XML属性
| 分類 |
XML属性 |
説明 |
| サイズ |
android:keyWidth |
Default width of a key, in pixels or percentage of display width. |
| android:keyHeight |
Default height of a key, in pixels or percentage of display width. |
| ギャップ |
android:horizontalGap |
キー間の水平方向のギャップの既定値 |
| android:verticalGap |
キー間の垂直方向のギャップの既定値 |
属性値の単位
| 分類 |
単位 |
説明 |
| 寸法 |
px |
pixels |
| dp |
density independent pixels |
| sp |
scaled pixels based based on preferred font size |
| in |
inches |
| mm |
millimeters |
| 割合 |
% |
基本サイズに対する割合 |
| %p |
親コンテナに対する割合 |
Dimensionリソース
| 分類 |
XML属性 |
説明 |
| |
android:keyboardMode |
Mode of the keyboard. |
| |
android:rowEdgeFlags |
行の配置フラグ
| 定数 |
値 |
説明 |
| top |
4 |
キーボードの上部に固定 |
| buttom |
8 |
キーボードの下部に固定 |
|
| サイズ |
android:keyWidth |
Default width of a key, in pixels or percentage of display width. |
| android:keyHeight |
Default height of a key, in pixels or percentage of display width. |
| ギャップ |
android:horizontalGap |
Default horizontal gap between keys. |
| android:verticalGap |
Default vertical gap between rows of keys. |
| 分類 |
XML属性 |
説明 |
| |
android:codes |
キーが押下されたときに出力されるUnicode値。複数の値を出力するにはカンマで区切る |
| |
android:keyLabel |
キーに表示されるラベル |
| |
android:keyIcon |
The icon to display on the key instead of the label. |
| |
android:keyOutputText |
The string of characters to output when this key is pressed. |
| |
android:keyEdgeFlags |
キーの配置フラグ
| 定数 |
値 |
説明 |
| left |
1 |
キーボードの左側に固定 |
| right |
2 |
キーボードの右側に固定 |
|
| サイズ |
android:keyWidth |
Default width of a key, in pixels or percentage of display width. |
| android:keyHeight |
Default height of a key, in pixels or percentage of display width. |
| ギャップ |
android:horizontalGap |
Default horizontal gap between keys. |
| ポップアップ |
android:popupCharacters |
The characters to display in the popup keyboard. |
| android:popupKeyboard |
The XML keyboard layout of any popup keyboard. |
| 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. |
レイアウト ファイルの読み込み
Keyboardクラスのコンストラクタで、レイアウト ファイルを指定することで読み込みます。
public Keyboard (Context context, int xmlLayoutResId)
たとえばキーボードのレイアウト ファイルをfoo.xmlという名前で作成し、これをres/xml/foo.xmlと配置したならば、
Keyboard keyboard = new Keyboard(this, R.xml.foo);
として読み込めます。