0

さて、あなたはこれを求めているような質問はほとんど見ていないかもしれません。 しかし、これらの質問/回答や、Googleのアンドロイドの入力方法ウェブページのほとんどすべてを読んでも、私はまだ悩んでいます。アンドロイド用のカスタムキーボードを作成する

最終的な目標は、カスタムキーボードを作成することです。もちろん、私の言語には特別な入力方法があります。

しかし、今回は、キーボードがポップアップしたときにカスタムビューを表示するだけです。私はqwerty.xmlファイルに基づいてデフォルトのレイアウトをポップすることができました。これはこのようなものです。

XML/qwerty.xml

<Keyboard xmlns:android="http://schemas.android.com/apk/res/android" 
android:keyWidth="10%p" 
android:horizontalGap="0px" 
android:verticalGap="0px" 
android:keyHeight="60dp" 
> 
<Row android:rowEdgeFlags="bottom"> 
    <Key android:codes="999" android:keyLabel="Settings" android:keyWidth="20%" android:keyEdgeFlags="left"/> 
    <Key android:codes="44" android:keyLabel="," android:keyWidth="7%p" /> 
    <Key android:codes="47" android:keyLabel="/" android:keyWidth="7%p" /> 
    <Key android:codes="32" android:keyLabel="SPACE" android:keyWidth="30%p" android:isRepeatable="true"/> 
    <Key android:codes="-5" android:keyLabel="DEL" android:keyWidth="18%p" android:isRepeatable="true"/> 
    <Key android:codes="-4" android:keyLabel="DONE" android:keyWidth="18%p" android:keyEdgeFlags="right"/> 
</Row> 

そしてInputMethodServiceを拡張する私のクラスでは、私は、入力ビューを作成し、このコードを持っています。

private KeyboardView myKeyView; 
private Keyboard keyboard; 

@Override 
public View onCreateInputView() { 
    myKeyView = (KeyboardView)getLayoutInflater().inflate(R.layout.keyboard, null); 
    keyboard = new Keyboard(this, R.xml.qwerty); 
    myKeyView.setKeyboard(keyboard); 
    myKeyView.setOnKeyboardActionListener(this); 
    return myKeyView; 
} 

そしてもちろん、私は私の元に私のカスタムビューを適用する上で問題があったので。 私はちょうど反対側にいくつかの努力をしました。 XMLでの設定キーを押すと、

<Key android:codes="999" android:keyLabel="Settings" android:keyWidth="20%" android:keyEdgeFlags="left"/> 

はそれがSettingsActivity

@Override 
public void onKey(int primaryCode, int[] keyCodes) { 
    if(primaryCode == 999) { 
     openSettings(); 
    } 
} 

public void openSettings() 
{ 
    Intent intent = new Intent(this, WRKeySettings.class); 
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
    startActivity(intent); 
} 

を呼び出しますそれはここまでうまく動作しますが、私は、このビューの問題にしています。

私は、アンドロイドデベロッパといくつかの記事を読んで、キーボードビューを拡張してカスタムビューを作成でき、この方法では何とかonDraw()でキーを描くことができると考えています。しかし、私はこれをすることに非常に苦労しています。

どのような提案も喜ばれます。ありがとう。

+0

質問を明確に理解するだけで、別のレイアウトをプログラムで作成したいですか?既存のものに変更を加えたいですか?別のアプリケーションで同じ「キーボード」を再利用したいですか?あなたはキーを "再描画"することができますが、それらは同じ機能を持つか、レイアウトにビューを追加してウィンドウを "やり直す"ことができます... – Bonatti

答えて

1

キーボードをカスタマイズするには、xmlフォルダの "qwerty"とレイアウトフォルダのキーボードを変更する必要があります。私はいくつかの例を紹介します:

これは、レイアウトフォルダに

<?xml version="1.0" encoding="UTF-8"?> 
<com.example.keyboard.MyKeyboardView 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/keyboard" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:layout_alignParentBottom="true" 
android:keyPreviewLayout="@layout/preview" 
android:keyBackground="@drawable/key_selector" 
android:shadowRadius="0.0" 
android:keyTextColor="#000000" 
/> 

を行くと、これはXMLフォルダに行く:あなたが言ったように

<?xml version="1.0" encoding="utf-8"?> 
<Keyboard xmlns:android="http://schemas.android.com/apk/res/android" 
android:keyWidth="10%p" 
android:keyHeight="8%p"> 

<Row android:verticalGap="1%p" android:horizontalGap="0.5%p" android:keyWidth="9.6%p"> 
    <Key android:codes="113" android:keyLabel="q" /> 
    <Key android:codes="119" android:keyLabel="w" /> 
    <Key android:codes="101" android:keyLabel="e" /> 
    <Key android:codes="114" android:keyLabel="r" /> 
    <Key android:codes="116" android:keyLabel="t" /> 
    <Key android:codes="121" android:keyLabel="y" /> 
    <Key android:codes="117" android:keyLabel="u" /> 
    <Key android:codes="105" android:keyLabel="i" /> 
    <Key android:codes="111" android:keyLabel="o" /> 
    <Key android:codes="112" android:keyLabel="p" /> 
</Row> 
<Row android:verticalGap="1%p" android:horizontalGap="0.5%p" android:keyWidth="9.6%p"> 
    <Key android:codes="97" android:keyLabel="a" android:keyEdgeFlags="left" android:horizontalGap="5%p" /> 
    <Key android:codes="115" android:keyLabel="s" /> 
    <Key android:codes="100" android:keyLabel="d" /> 
    <Key android:codes="102" android:keyLabel="f" /> 
    <Key android:codes="103" android:keyLabel="g" /> 
    <Key android:codes="104" android:keyLabel="h" /> 
    <Key android:codes="106" android:keyLabel="j" /> 
    <Key android:codes="107" android:keyLabel="k" /> 
    <Key android:codes="108" android:keyLabel="l" /> 
</Row> 
<Row android:verticalGap="1%p" android:horizontalGap="0.5%p" android:keyWidth="9.6%p"> 
    <Key android:codes="3"  android:keyIcon="@drawable/keyboard_shift_off_normal" 
     android:keyWidth="13.7%p"/> 
    <Key android:codes="122" android:keyLabel="z" android:horizontalGap="1%p"/> 
    <Key android:codes="120" android:keyLabel="x" /> 
    <Key android:codes="99"  android:keyLabel="c" /> 
    <Key android:codes="118" android:keyLabel="v" /> 
    <Key android:codes="98"  android:keyLabel="b" /> 
    <Key android:codes="110" android:keyLabel="n" /> 
    <Key android:codes="109" android:keyLabel="m" /> 
    <Key android:codes="-5"  android:keyIcon="@drawable/sym_keyboard_delete_dim" 
     android:keyWidth="13.7%p" 
     android:horizontalGap="1%p"/> 
</Row> 
<Row android:verticalGap="1%p" android:horizontalGap="0.5%p" android:keyWidth="9.6%p"> 
    <Key android:codes="-16" android:keyIcon="@drawable/keyboard_symbol" 
     android:keyWidth="18.7%p"/> 
    <Key android:codes="44"  android:keyLabel="," android:horizontalGap="1%p"/> 
    <Key android:codes="32"  android:keyIcon="@drawable/sym_keyboard_feedback_space" android:keyWidth="40%p"/> 
    <Key android:codes="46"  android:keyLabel="."/> 
    <Key android:codes="-3"  android:keyIcon="@drawable/keyboard_go" 
     android:keyWidth="18.5%p" android:horizontalGap="1%p"/> 
</Row> 
</Keyboard> 

、あなたがキーボードからクラスを拡張することができますレイアウトは、キーボードイベントをカスタマイズするためのもので、onTouch、onLongKeyPress、

などがあります。
+0

をできるだけ具体的にするまあ、不幸にも、これは私が望む特定の答えではありません。私はちょうどこの事を働かせ、これについての特定のガイドを書く方法を見つけようとするつもりです。 – luopleming

関連する問題