我有自定义键盘带红色按钮当我按下例如数字1时颜色变为蓝色当我从屏幕拉动手指回到红色时,我想保持蓝色任何人都知道怎么做这里的我的颜色变化(按下)xml
<selector xmlns:android="http://schemas.android.com/apk/res/android"
>
<item
android:state_pressed="true"
android:drawable="@drawable/pressed" />
<item
android:state_checkable="true"
android:state_pressed="true"
android:drawable="@drawable/download" />
<item android:drawable="@drawable/red"/>
</selector>
检查一下:
public class BasicOnKeyboardActionListener implements KeyboardView.OnKeyboardActionListener {
private Activity mTargetActivity;
public BasicOnKeyboardActionListener(Activity targetActivity) {
mTargetActivity = targetActivity;
}
@Override
public void swipeUp() {
// TODO Auto-generated method stub
}
@Override
public void swipeRight() {
// TODO Auto-generated method stub
}
@Override
public void swipeLeft() {
// TODO Auto-generated method stub
}
@Override
public void swipeDown() {
// TODO Auto-generated method stub
}
@Override
public void onText(CharSequence text) {
// TODO Auto-generated method stub
}
@Override
public void onRelease(int primaryCode) {
}
// TODO Auto-generated method stub
@Override
public void onPress(int primaryCode) {
}
// TODO Auto-generated method stub
@Override
public void onKey(int primaryCode, int[] keyCodes)
{
long eventTime = System.currentTimeMillis();
KeyEvent event = new KeyEvent(eventTime, eventTime,
KeyEvent.ACTION_DOWN, primaryCode, 0, 0 ,0 , 0,
KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TOUCH_MODE);
mTargetActivity.dispatchKeyEvent(event);
}
答案 0 :(得分:0)
Add this methods to the `keyboardListner`
public class SimpleIME extends InputMethodService
implements OnKeyboardActionListener{
private KeyboardView kv;
private Keyboard keyboard;
private boolean caps = false;
@Override
public void onKey(int primaryCode, int[] keyCodes) {
}
@Override
public void onPress(int primaryCode) {
}
@Override
public void onRelease(int primaryCode) {
}
@Override
public void onText(CharSequence text) {
}
@Override
public void swipeDown() {
}
@Override
public void swipeLeft() {
}
@Override
public void swipeRight() {
}
@Override
public void swipeUp() {
}
}
并更改onpressed
和OnReleased
颜色
有关详细信息,请点击链接... click here
答案 1 :(得分:0)
试试这个
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Button Focused-->
<item android:state_focused="true"
android:state_pressed="false"
android:drawable="@drawable/blue"
/>
<!-- Button Focused Pressed-->
<item android:state_focused="true"
android:state_pressed="true"
android:drawable="@drawable/blue"
/>
<!-- Button Pressed-->
<item android:state_focused="false"
android:state_pressed="true"
android:drawable="@drawable/blue"
/>
<!-- Button not focused and Pressed-->
<item android:state_focused="false"
android:state_pressed="false"
android:state_selected="true"
android:drawable="@drawable/blue"/>
<!-- Button Default Image-->
<item android:drawable="@drawable/red"/>
</selector>