Pages

Wednesday, November 7, 2012

Show or Hide soft keyboard on opening a dialog or activity in android

For showing the soft keyboard on entering into the activity or to the dailog we can use this coding.


InputMethodManager show = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
show.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);





and for hiding the keyboard





InputMethodManager hide = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
hide.hideSoftInputFromWindow(**YOUR_VIEW**.getWindowToken(),0);


If you want virtual Keyboard on start of activity. Try below code.

 Your Virtyual key board open on starting of activity.



        **YOUR_VIEW**.postDelayed(new Runnable() {
            @Override
            public void run() {
                InputMethodManager keyboard = (InputMethodManager)
                getSystemService(Context.INPUT_METHOD_SERVICE);
                keyboard.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); 
            }
        },200);

No comments:

Post a Comment