Leo
Leo

Reputation: 3143

How to show custom keyboard

I have EditText and I need to show my custom keyboard when user click this EditText. (I don't need to set this keyboard to defaut, just show it once with my editView) How to make it?

Upvotes: 0

Views: 437

Answers (2)

Gabe Sechan
Gabe Sechan

Reputation: 93561

In the xml, set the following

android:inputMethod="com.myapp.mykeyboard"

Upvotes: 1

MRX
MRX

Reputation: 1442

Make a layout for your keyboard and in your oncreate method do something like this

    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);

}

Upvotes: 1

Related Questions