2015-08-21 2 views
0

у меня есть эта клавиатура: enter image description hereпользовательских цветов на softkeyboard

я думаю клавиатуры приходят из учебника основной клавиатуры.

Я хочу, чтобы изменить цвет фона для каждого ключа:

Здесь я положил все ключевые:

<Keyboard xmlns:android="http://schemas.android.com/apk/res/android" 
android:keyWidth="10%p" 
android:horizontalGap="0px" 
android:verticalGap="0px" 
android:keyHeight="@dimen/key_height"> 

<Row> 
    <Key android:codes="113" android:keyLabel="q" android:keyEdgeFlags="left"/> 
    <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" android:keyEdgeFlags="right"/> 
</Row> 

Я не знаю, если я могу изменить стиль оттуда

Update My KeyboardView:

<android.inputmethodservice.KeyboardView 
     android:id="@+id/keyboardView" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="0dp" 
     android:focusableInTouchMode="true" 
     android:keyBackground="@drawable/message_bg" 
     android:keyPreviewLayout="@layout/preview"> 
</android.inputmethodservice.KeyboardView> 

Keyboard.java

public void onInitializeInterface() { 

    qwertyKeyboard = new Keyboard(this, R.xml.qwerty); 

    symbolsKeyboard = new Keyboard(this, R.xml.symbols); 

    symbolsShiftedKeyboard = new Keyboard(this, R.xml.symbols_shift); 

    fillKeyboard = (LinearLayout) getLayoutInflater().inflate(R.layout.fill_keyboard, null); 

    dialogAccounts = new Builder(this); 

    dialogAllAccounts = new Builder(this); 

    usersTextView = (Button) fillKeyboard.findViewById(R.id.userTextView); 

    noCredentials = (Button) fillKeyboard.findViewById(R.id.noCredentials); 

} 

/** 
* Select the view in the keyboard depending of the Globals.isLoged 
*/ 
@Override 
public View onCreateInputView() { 

    Globals.isKeyboard = true; 

    Globals.tokenKeyboard = this.getWindow().getWindow().getAttributes().token; 

    database = new PwdDatabaseHelper(this); 
    loginKeyboard = (LinearLayout) getLayoutInflater().inflate(R.layout.log_keyboard, null); 

    if (!Globals.isLoged) { 

     myMasterPassword = (EditText) loginKeyboard.findViewById(R.id.masterPasswordKeyboard); 

     currentKeyboardView = (KeyboardView) loginKeyboard.findViewById(R.id.keyboardView); 

     currentKeyboardView.setKeyboard(qwertyKeyboard); 

     currentKeyboardView.setOnKeyboardActionListener(this); 

     return loginKeyboard; 
    } else { 

     if (fillUsersAndPass() != 0) { 
      currentKeyboardView = (KeyboardView) fillKeyboard.findViewById(R.id.keyboardView); 
      currentKeyboardView.setKeyboard(qwertyKeyboard); 
      currentKeyboardView.setOnKeyboardActionListener(this); 
      noCredentials.setVisibility(View.GONE); 

      usersTextView.setVisibility(View.VISIBLE); 

      return fillKeyboard; 
     } else { 

      currentKeyboardView = (KeyboardView) fillKeyboard.findViewById(R.id.keyboardView); 
      noCredentials.setVisibility(View.VISIBLE); 
      usersTextView.setVisibility(View.GONE); 
      currentKeyboardView.setKeyboard(qwertyKeyboard); 
      currentKeyboardView.setOnKeyboardActionListener(this); 
      return fillKeyboard; 
     } 

    } 
} 

Update 2

keyboard.xml

<?xml version="1.0" encoding="utf-8"?> 
 
<shape xmlns:android="http://schemas.android.com/apk/res/android" > 
 
     
 
<item android:state_pressed="true" 
 
     android:color="#8e44ad"/> <!-- pressed --> 
 
<item android:state_focused="true" 
 
     android:color="#e67e22"/> <!-- focused --> 
 
<item android:color="#e74c3c"/> <!--default --> 
 

 
</shape>

ответ

2

Вы можете изменить ключевые фоны с вашего KeyboardView. В вашем XML, добавьте в ваш KeyboardView:

android:keyBackground="@drawable/yourDrawable" 
android:keyPreviewLayout="@layout/yourLayout" 

Где yourDrawable это вытяжка файл (Это не может быть изображения), и yourLayout является макетом с родительской точкой зрения, установленным в качестве TextView.

Для получения дополнительной информации: http://developer.android.com/reference/android/inputmethodservice/KeyboardView.html

Edit:

Как Google Docs говорят:

андроида: keyBackground

Изображение ключа. Это изображение должно быть StateListDrawable со следующими возможными состояниями: нормальным, нажатым, проверяемым, проверяемым + нажатым, проверяемым + отмеченным, checkable + checked + нажатым.

Таким образом, вам нужно будет создать файл с возможностью рисования, а не изображение.

Пример:

<selector xmlns:android="http://schemas.android.com/apk/res/android"> 

    <item 
     android:state_pressed="true" 
     android:color="#8e44ad" /> <!-- pressed --> 

    <item 
     android:state_focused="true" 
     android:color="#e67e22" /> <!-- focused --> 

    <item 
     android:color="#e74c3c" /> <!-- default --> 

</selector> 

Ссылка: http://developer.android.com/reference/android/inputmethodservice/KeyboardView.html#attr_android:keyBackground

+0

я имею keyPreviewLayout и она работает, но keyBackground не делают, по-прежнему показывают тот же фон – GusDev

+0

Что вы пишете там, как ваш Drawable? Файл изображения или формы? –

+0

изображение, его файл формы, правильно? – GusDev