如何显示自定义键盘

时间:2013-02-18 07:53:41

标签: android keyboard android-edittext

我有EditText,当用户单击此EditText时,我需要显示我的自定义键盘。 (我不需要将此键盘设置为defaut,只需使用我的editView显示一次)如何制作?

2 个答案:

答案 0 :(得分:1)

在xml中,设置以下

android:inputMethod="com.myapp.mykeyboard"

答案 1 :(得分:1)

为键盘制作布局,并在oncreate方法中执行类似的操作

    setContentView(R.layout.main);
        // adjusting key regarding window sizes
        setKeys();
        setFrow();
        setSrow();
        setTrow();
        setForow();
        mEt = (EditText) findViewById(R.id.xEt);
        mEt.setOnTouchListener(this);
        mEt.setOnFocusChangeListener(this);
        mEt1 = (EditText) findViewById(R.id.et1);

        mEt1.setOnTouchListener(this);
        mEt1.setOnFocusChangeListener(this);
        mEt.setOnClickListener(this);
        mEt1.setOnClickListener(this);
        mLayout = (RelativeLayout) findViewById(R.id.xK1);
        mKLayout = (RelativeLayout) findViewById(R.id.xKeyBoard);


@Override
public boolean onTouch(View v, MotionEvent event) {
    if (v == mEt) {
        hideDefaultKeyboard();
        enableKeyboard();

    }
    if (v == mEt1) {
        hideDefaultKeyboard();
        enableKeyboard();

    }
    return true;
}
private void hideDefaultKeyboard() {
    getWindow().setSoftInputMode(
            WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

}
private void enableKeyboard() {

    mLayout.setVisibility(RelativeLayout.VISIBLE);
    mKLayout.setVisibility(RelativeLayout.VISIBLE);

}

// Disable customized keyboard
private void disableKeyboard() {
    mLayout.setVisibility(RelativeLayout.INVISIBLE);
    mKLayout.setVisibility(RelativeLayout.INVISIBLE);

}