How to remove repeatable keys, key preview of the Android custom keyboard
How to remove repeating keys, key preview of Android Custom Keyboard. I used following method to remove key preview of the keys that I want. But that method is not working for repeatable keys. (android:isRepeatable="true") If the key is not repeatable, following method is working.
delete key xml
<Key android:codes="-5"
android:keyWidth="13%p"
android:keyIcon="@drawable/ic_key_delete_white"
android:keyBackground="@color/dark_key_background"
android:isRepeatable="true"
android:horizontalGap="3.5%p"
android:keyEdgeFlags="right"/>
Input method service Class
@Override
public void onPress(int primaryCode) {
if (primaryCode == -1
|| primaryCode == -5){
kv.setPreviewEnabled(false);
}
}
@Override
public void onRelease(int primaryCode) {
if(primaryCode == -1
|| primaryCode == -5){
kv.setPreviewEnabled(true);
}
}
反转setPreviewEnabled标志..
public void onCreate() {
mInputView.setPreviewEnabled(false);
}
public void onPress(int primaryCode) {
if (primaryCode==-1||primaryCode==-2||primaryCode==-5||primaryCode==-4){
} else {
mInputView.setPreviewEnabled(true);
}
}
public void onRelease(int primaryCode) {
mInputView.setPreviewEnabled(false);
}
In following example we have two repeatable keys (Space and Delete)
STEP 1: set PreviewEnabled to "false" in onCreateInputView() :
kv.setPreviewEnabled(false);
STEP 2: add following if-else statement in onPress() :
public void onPress(int primaryCode)
{
if (!(primaryCode==32||primaryCode==Keyboard.KEYCODE_DELETE))
{
kv.setPreviewEnabled(true);
}
else
{
kv.setPreviewEnabled(false);
}
}
STEP 3: set PreviewEnabled to "false" in onRelease() :
public void onRelease(int primaryCode)
{
kv.setPreviewEnabled(false);
}
链接地址: http://www.djcxy.com/p/83876.html
上一篇: 不公正的链接错误