2013-08-17 9 views
5

私はカスタムキーボードアプリケーションを開発中です。私はKeyboardViewクラスのキーや背景色を別のテーマに設定し、SoftKeyboardのonCreateInputView()でキーカラーを取得する必要がありますInputMethodServiceクラスを拡張します。カスタムAndroidキーボードでKeyboardViewクラスのキーの色を変更するには?

しかし、特定のキーの色や背景を変更できるように、キーコードに応じて特定のキーを取得する方法がわかりません。 keyBackground = ".."

例:

input.xmlに:

<com.example.KeyboardView 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/keyboard" 
     android:layout_alignParentBottom="true" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:keyBackground="@drawable/blue_key" 
     /> 

input1.xml:

<com.example.KeyboardView 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@+id/keyboard" 
      android:layout_alignParentBottom="true" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:keyBackground="@drawable/red_key" 
      /> 

任意切り抜い入力レイアウト使用Androidの

+0

これまでに何を試しましたか?試したことのコードを入力すると、助けを得るのに役立ちます。 –

+0

私はinput.xmlとinput1.xmlに設定しました – user

+0

実行時にキーコードを取得する必要があります。つまり、異なるキーカラーですinputc.xml、input1.xml、input2.xmlを使用しました。 、input1.xmlの場合は青の組み合わせ、背景の色は赤とオレンジになります.. input2.xmlと同じように、私はこの方法を知りません。 – user

答えて

8

OnCreateInputViewメソッドの場合:

あなたはすでにそれを行って、何あなたが必要とする特殊なキーに異なる背景を設定することですしている場合

setInputView(onCreateInputView()); 

@Override public View onCreateInputView() { 
    if(theme == 1) 
     mInputView = (KeyboardView) getLayoutInflater().inflate(R.xml.input , null); 
    else 
     mInputView = (KeyboardView) getLayoutInflater().inflate(R.xml.input1 , null); 
    mInputView.setOnKeyboardActionListener(this); 
    mInputView.setKeyboard(mQwertyKeyboard); 
    mComposing.setLength(0); 
    return mInputView; 
} 

及び方法の終わりには、これを追加しonStartInput。多分、私が書いた問題の解決策があなたを助けるでしょう。https://stackoverflow.com/a/18354298/2683898

おはよう! :)

+0

また、背景は描画可能である必要はありません。それは色資源でもあります。 –

関連する問題