Brother recently needed to make a custom keyboard, some of the information found on the Internet. Use android.inputmethodservice.KeyboardView this thing to implement custom keyboard encountered a few small problems you great God who seek to answer.



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 && editable.length ()> 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:
xmlns: tools = "http://schemas.android.com/tools"
android: layout_width = "match_parent"
android: layout_height = "match_parent"
android: orientation = "vertical">android: id = "@ + id / edt_text"
android: layout_width = "fill_parent"
android: layout_height = "wrap_content"
android: hint = "@ string / keyboard" />android: layout_width = "fill_parent"
android: layout_height = "wrap_content">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" />
Custom Keyboard Layout:
android: keyWidth = "33% p"
android: horizontalGap = "0px"
android: verticalGap = "0px"
android: keyHeight = "46dip">|
<-!
<- Android:! KeyEdgeFlags = "right" ->
<- Android:! KeyIcon = "@ drawable / sym_keyboard_left" /> ->|
<-!
<- Android:! KeyEdgeFlags = "right" ->
<- Android:! KeyIcon = "@ drawable / sym_keyboard_right" /> ->|
<-!
<- Android:! KeyHeight = "92dip" ->
<- Android:! KeyEdgeFlags = "right" ->
<- Android:! IsRepeatable = "true" two ->
<- Android:! KeyLabel = "completed" /> ->|
<-!->
Reply:

Reply:
master will not come here. You do not see a bunch of question marks? Asked few posts restoration, it has the resources of the whole came. . . Haha good or Baidu
Reply:

Reply:
http://download.csdn.net/detail/yuanjiangxujin/5641095
Reply:
http://download.csdn.net/detail/yuanjiangxujin/5641095
And he's not the same as it is also a little problem with the cursor is not where you where to click on Show
Reply:
The second problem has been solved slightly due to construction projects on the Application node in the list of files by default added android: theme = "@ style / AppTheme" So the word white white background see.

The first words of the cursor problem how to solve?
Reply:
The first problem is to get to distinguish what version

Reply:
The landlord helped me too.
No comments:
Post a Comment