2011-01-14 36 views
1

我对开发Android应用程序很陌生,面临 困难。定制键盘

我想要做的是使用特定的键盘,当我点击一个 EditText。到目前为止,我发现了KeyboardKeyboardView 类,但我还没有成功做到我想要的。

下面是我在哪里描述:

  • 我在一个XML文件中所描述我的键盘,
  • 我创建了一个“KeyboardView”对象,
  • clavier=new KeyboardView(activité, (AttributeSet)findViewById(R.xml.clavier_numerique));
  • 初始化
  • 但我不知道如何用此 自定义键盘替换标准键盘。

我做错了什么?我还应该做什么?

在此先感谢您花费时间来帮助我。

回答

0

您需要指定XML中的一个inputType

<EditText android:inputType="textUri"/> 

或从代码做:

EditText input; 
input.setInputType(InputType.TYPE_CLASS_NUMBER); 

您可以阅读可用inputType小号here

1

首先,你要决定你从键盘想要的东西:

,如果你只是想改变你可以做到这一点从Macarse
第一个答案 如果你想有一个完整的自定义键盘,你应该使用Keyboard号和KeyboardView类的第二个项目

2

你应该使用这样的事情:

//retrieve the keyboard view from xml 
    kbdV= (KeyboardView) findViewById(R.id.kbd); 

    //set the keyboard layout to the layout you defined in res/xml/keyboard_layout.xml 
    kbdV.setKeyboard(new Keyboard(this,R.xml.keyboard_layout)); //defines the keyboard layout 

    //add a keyboard action listener 
    kbdV.setOnKeyboardActionListener(new KeyboardView.OnKeyboardActionListener(){ 
     public void onKey(int primaryCode, int[] keyCodes) { 
      handlePress(primaryCode, keyCodes); // callback to handle keypresses 
     } 
     public void onPress(int primaryCode) {} 
     public void onRelease(int primaryCode) {} 
     public void onText(CharSequence text) {} 
     public void swipeDown() {} 
     public void swipeLeft() {} 
     public void swipeRight() {} 
     public void swipeUp() {} 
    }); 

类似的布局xml文件为此:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

<!-- your widgets here --> 

<KeyboardView android:id="@+id/kbd" android:layout_width="fill_parent" android:layout_height="wrap_content"/> 
</LinearLayout> 
0

当你用键盘=新KeyboardView(活动, (AttributeSet中)findViewById(R.xml.clavier_numerique)的EditText编辑)初始化; 您可以在其中传输EditText对象。并隐藏标准键盘,像这样显示自定义的KeyboardView。

public void showKeyboard() { 
if (edit != null) { 
     InputMethodManager imm = (InputMethodManager)mActivity.getSystemService(Context.INPUT_METHOD_SERVICE); 
     imm.hideSoftInputFromWindow(edit.getWindowToken(), 0); 
    } 

    keyboardView.setVisibility(View.VISIBLE); 
    keyboardView.setEnabled(true); 
}