user2567369
user2567369

Reputation:

Close/hide the Android Soft Keyboard and Show custom keyboard

I have make my own keyboard, in my activity there is an option (English-Hindi, Hindi-English) when user choose English-Hindi the default keyboard will be open and hide my custom keyboard or when user select Hindi-English option the default keyboard will be hide and custom keyboard will be opened up

below is my source code,

private EditText mEt;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    mEt = (EditText) findViewById(R.id.searchText);
    enableHindiKeyboard();
    hideDefaultKeyboard();
 }

For hiding default keyboard

private void hideDefaultKeyboard() {
    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(mEt.getWindowToken(), 0);
} 

For enabling Hindi Keyboard

public void enableHindiKeyboard() {      
    try {
            for (int i = 0; i < mB.length; i++)
                mB[i].setOnClickListener(this);

            mBSpace.setOnClickListener(this);
            mBdone.setOnClickListener(this);
            mBack.setOnClickListener(this);
            mBChange.setOnClickListener(this);
            mNum.setOnClickListener(this);
            mEt.setOnTouchListener(MainActivity.this);
            mEt.setOnFocusChangeListener(MainActivity.this);
            mEt.setOnClickListener(MainActivity.this);

        } catch (Exception e) {
            Log.w(getClass().getName(), e.toString());
        }
 }

in this problem when i start my activity at that time i want Hindi Keyboard should be display and Default keyboard should be invisible but the problem is that

hindi keyboard will not be shown at startup and Default keyboard will popup

Upvotes: 2

Views: 1563

Answers (4)

Kuldeep Sakhiya
Kuldeep Sakhiya

Reputation: 3252

try
{
     InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE);
     inputMethodManager.toggleSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.SHOW_FORCED, 0);
}
catch (Exception e)
{
     e.printStackTrace();
}

Upvotes: 0

Hareshkumar Chhelana
Hareshkumar Chhelana

Reputation: 24848

// try this
    public void showSoftKeyboard() {
        try {
            InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE);
            inputMethodManager.toggleSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.SHOW_FORCED, 0);
        } catch (Exception e) {
            e.printStackTrace();
        }
     }

    public void hideSoftKeyboard() {
        try {
            InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE);
            inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

Upvotes: 1

vish
vish

Reputation: 168

try this

In your AndroidManifest.xml:

<activity android:name="com.your.package.ActivityName"
      android:windowSoftInputMode="stateHidden"  />

Upvotes: 0

RussVirtuoso
RussVirtuoso

Reputation: 888

Use this to hide the keyboard imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); and to show the keyboard call it again. Call first the hideDefaultKeyboard(); before enableHindiKeyboard(); Hope it helps.

Upvotes: 0

Related Questions