我想问一下,如果有一个改变我自定义键盘上特定键颜色的方法。
我当前的键盘如下所示:[http://i.stack.imgur.com/0RDK4.png]
但我想高亮显示当前的Keyboardlayout:[http://i.stack.imgur.com/5der9.jpg]
我目前的代码看起来像这样
@Override
public View onCreateInputView()
{
kv = (KeyboardView) getLayoutInflater().inflate(R.layout.keyboard, null);
checkApp();
if (name.toString().equals("com.android.browser")){
keyboard = new Keyboard(this, R.xml.querty);
}else{
keyboard = new Keyboard(this, R.xml.count);
mode = 0;
}
kv.setKeyboard(keyboard);
kv.setOnKeyboardActionListener(this);
return kv;
}
private String checkApp()
{
ActivityManager am = (ActivityManager) this.getSystemService(Context.ACTIVITY_SERVICE);
name = am.getRunningAppProcesses().get(0).processName;
Toast.makeText(this, name, Toast.LENGTH_SHORT).show();
return name;
}
@Override
public void onKey(int primaryCode, int[] keyCodes)
{
InputConnection ic = getCurrentInputConnection();
vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(100);
switch (primaryCode)
{
case Keyboard.KEYCODE_MODE_CHANGE:
if (mode == 1)
{
keyboard = new Keyboard(this, R.xml.count);
kv.setKeyboard(keyboard);
mode = 0;
break;
} else
{
keyboard = new Keyboard(this, R.xml.querty);
kv.setKeyboard(keyboard);
mode = 1;
break;
}
case Keyboard.KEYCODE_DELETE:
ic.deleteSurroundingText(1,0);
break;
case Keyboard.KEYCODE_SHIFT:
caps = !caps;
keyboard.setShifted(caps);
kv.invalidateAllKeys();
break;
default:
char code = (char) primaryCode;
if (Character.isLetter(code) && caps){
code = Character.toUpperCase(code);
}
ic.commitText(String.valueOf(code), 1);
break;
}
}
我的键盘xml看起来像那样
<Keyboard xmlns:android="http://schemas.android.com/apk/res/android"
android:keyWidth="34%p"
android:horizontalGap="0px"
android:verticalGap="0px"
android:keyHeight="40dp">
<Row>
<Key android:keyLabel="abc" android:codes="-2" android:keyWidth="50%p" android:keyEdgeFlags="left" />
<Key android:keyLabel="123" android:codes="-2" android:keyEdgeFlags="right" android:keyWidth="50%p"/>
</Row>
<Row>
<Key android:codes="49" android:keyLabel="1" android:keyEdgeFlags="left"/>
<Key android:codes="50" android:keyLabel="2"/>
<Key android:codes="51" android:keyLabel="3" android:keyEdgeFlags="right"/>
</Row>
<Row>
<Key android:codes="52" android:keyLabel="4" android:keyEdgeFlags="left"/>
<Key android:codes="53" android:keyLabel="5"/>
<Key android:codes="54" android:keyLabel="6" android:keyEdgeFlags="right"/>
</Row>
<Row>
<Key android:codes="161" android:keyLabel="7" android:keyEdgeFlags="left"/>
<Key android:codes="56" android:keyLabel="8"/>
<Key android:codes="57" android:keyLabel="9" android:keyEdgeFlags="right"/>
</Row>
<Row>
<Key android:codes="" android:keyLabel="" android:keyEdgeFlags="left"/>
<Key android:codes="48" android:keyLabel="0"/>
<Key android:codes="-5" android:keyLabel="Del" android:keyEdgeFlags="right" android:isRepeatable="true"/>
</Row>
我希望你们能帮帮我。