Monday, January 11, 2016

The EditText on Android using a custom keyboard problems




            


Brother recently to do a custom keyboard, some of the information found on the Internet. Use android.inputmethodservice.KeyboardView this thing to implement custom keyboard encountered a few minor problems have to ask you to answer the great God.



 
keyboardView.setKeyboard (new Keyboard (this, R.xml.qwerty));
keyboardView.setEnabled (true);
keyboardView.setPreviewEnabled (true);

edt_text.setOnTouchListener (new OnTouchListener ()
{

public boolean onTouch (View v, MotionEvent event)
{
int inputType = edt_text.getInputType ();
edt_text.setInputType (InputType.TYPE_NULL); // let the system keyboard does not pop up
showKeyboard ();
edt_text.setInputType (inputType);
return false;
}
});

keyboardView.setOnKeyboardActionListener (new OnKeyboardActionListener ()
{
public void onKey (int primaryCode, int [] keyCodes)
{
Editable editable = edt_text.getText ();
int start = edt_text.getSelectionStart ();
if (primaryCode == Keyboard.KEYCODE_CANCEL)
{
hideKeyboard ();
}
else if (primaryCode == Keyboard.KEYCODE_DELETE)
{
if (editable = null & amp;! & amp; editable.length () & gt; 0)
{
editable.delete (start - 1, start);
}
}
else
{
editable.insert (start, Character.toString ((char) primaryCode));
}

}

public void swipeUp ()
{
// TODO Auto-generated method stub

}

public void swipeRight ()
{
// TODO Auto-generated method stub

}

public void swipeLeft ()
{
// TODO Auto-generated method stub

}

public void swipeDown ()
{
// TODO Auto-generated method stub

}

public void onText (CharSequence text)
{
// TODO Auto-generated method stub

}

public void onRelease (int primaryCode)
{
// TODO Auto-generated method stub

}

public void onPress (int primaryCode)
{
// TODO Auto-generated method stub

}

});
private void showKeyboard ()
{
int visibility = keyboardView.getVisibility ();
if (visibility == View.GONE || visibility == View.INVISIBLE)
{
keyboardView.setVisibility (View.VISIBLE);
System.out.println ("showKeyboard");
}
}

private void hideKeyboard ()
{
int visibility = keyboardView.getVisibility ();
if (visibility == View.VISIBLE)
{
keyboardView.setVisibility (View.INVISIBLE);
System.out.println ("hideKeyboard");
}
}

Activity layout:
 
& Lt; LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"
xmlns: tools = "http://schemas.android.com/tools"
android: layout_width = "match_parent"
android: layout_height = "match_parent"
android: orientation = "vertical" & gt;

& Lt; EditText
android: id = "@ + id / edt_text"
android: layout_width = "fill_parent"
android: layout_height = "wrap_content"
android: hint = "@ string / keyboard" / & gt;

& Lt; RelativeLayout
android: layout_width = "fill_parent"
android: layout_height = "wrap_content" & gt;

& Lt; android.inputmethodservice.KeyboardView
android: id = "@ + id / keyboard_view"
android: layout_width = "fill_parent"
android: layout_height = "wrap_content"
android: layout_alignParentBottom = "true"
android: focusable = "true"
android: focusableInTouchMode = "true"
android: visibility = "gone" / & gt;
& Lt; / RelativeLayout & gt;

& Lt; / LinearLayout & gt;

Custom Keyboard Layout:
 
& Lt;? Xml version = "1.0" encoding = "utf-8" & gt;?
& Lt; Keyboard xmlns: android = "http://schemas.android.com/apk/res/android"
android: keyWidth = "33% p"
android: horizontalGap = "0px"
android: verticalGap = "0px"
android: keyHeight = "46dip" & gt;
& Lt; Row & gt;
& Lt; Key android: codes = "49" android: keyLabel = "1" / & gt;
& Lt; Key android: codes = "50" android: keyLabel = "2" / & gt;
& Lt; Key android: codes = "51" android: keyLabel = "3" / & gt;
& Lt; - & lt; Key android:! Codes = "57419" - & gt;
& Lt; - android:! KeyEdgeFlags = "right" - & gt;
& Lt; - android:! KeyIcon = "@ drawable / sym_keyboard_left" / & gt; - & gt;
& Lt; / Row & gt;
& Lt; Row & gt;
& Lt; Key android: codes = "52" android: keyLabel = "4" / & gt;
& Lt; Key android: codes = "53" android: keyLabel = "5" / & gt;
& Lt; Key android: codes = "54" android: keyLabel = "6" / & gt;
& Lt; - & lt; Key android:! Codes = "57421" - & gt;
& Lt; - android:! KeyEdgeFlags = "right" - & gt;
& Lt; - android:! KeyIcon = "@ drawable / sym_keyboard_right" / & gt; - & gt;
& Lt; / Row & gt;
& Lt; Row & gt;
& Lt; Key android: codes = "55" android: keyLabel = "7" / & gt;
& Lt; Key android: codes = "56" android: keyLabel = "8" / & gt;
& Lt; Key android: codes = "57" android: keyLabel = "9" / & gt;
& Lt; - & lt; Key android:! Codes = "- 3" - & gt;
& Lt; - android:! KeyHeight = "92dip" - & gt;
& Lt; - android:! KeyEdgeFlags = "right" - & gt;
& Lt; - android:! IsRepeatable = "true" two - & gt;
& Lt; - android:! KeyLabel = "complete" / & gt; - & gt;
& Lt; / Row & gt;
& Lt; Row & gt;
& Lt; Key android: codes = "42" android: keyLabel = "*" / & gt;
& Lt; Key android: codes = "48" android: keyLabel = "0" / & gt;
& Lt; Key android: codes = "35" android: keyLabel = "#" / & gt;
& Lt; - & lt; Key android:! Codes = "- 5" android: keyIcon = "@ drawable / sym_keyboard_delete" / & gt; - & gt;
& Lt; / Row & gt;
& Lt; / Keyboard & gt;


Reply:
how nobody to answer ah. . .
Reply:
quote 1 floor j249050279 reply:
how nobody to answer ah. . .
master will not come here. You do not see a bunch of question marks? Question posts restoration few, have the resources of the on the whole came. . . Haha good or Baidu
Reply:
quote the second floor dengliulin reply:
Quote: quote 1 floor j249050279 reply:

how nobody to answer ah. . .
master will not come here. You do not see a bunch of question marks? Question posts restoration few, have the resources of the on the whole came. . . Haha still Baidu good


Reply:
http://download.csdn.net/detail/yuanjiangxujin/5641095
Reply:
quote 4th floor yuanjiangxujin reply:
http://download.csdn.net/detail/yuanjiangxujin/5641095

It is not the same and he's also a little problem with the cursor nor where to click on where you Display
Reply:
The second issue has been resolved slightly due to the construction project on the Application node list file default plus the android: theme = "@ style / AppTheme" So the word white white background see.
The first question saying that the cursor of the how to solve?
Reply:
The first issue also get to distinguish between what version
Reply:
Landlord very helpful for me.
Reply:
What I want to thank the landlord
Reply:
if (android.os.Build.VERSION.SDK_INT & lt; = 10) {
edit.setInputType (InputType.TYPE_NULL);
} Else {
getWindow (). setSoftInputMode (
WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
try {
Class & lt; EditText & gt; cls = EditText.class;
Method setShowSoftInputOnFocus;
setShowSoftInputOnFocus = cls.getMethod (
"SetShowSoftInputOnFocus", boolean.class);
setShowSoftInputOnFocus.setAccessible (true);
setShowSoftInputOnFocus.invoke (edit, false);
} Catch (Exception e) {
e.printStackTrace ();
}
}

The better point
Reply:
setInputType (InputType.TYPE_NULL);
Off label did not, can not use this ah
Reply:
Second problem there is no better solution?
Reply:
The same question, the second question still do not understand
Reply:
Second problem solving ~ ~ there solutions?
Reply:
Click the bomb box how to remove the unwanted effect ah pro ~

No comments:

Post a Comment