跳至主要内容

how to close input method in android code


open input method activity window:

InputMethodManager inputMethodManager =     (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);

// accept input text

imm.showSoftInput(submitBt,InputMethodManager.SHOW_FORCED);

close input method activity window

InputMethodManager inputMethodManager = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);

inputMethodManager.hideSoftInputFromWindow(
        OpeListActivity.this.getCurrentFocus().getWindowToken(),InputMethodManager.HIDE_NOT_ALWAYS);

if input method activity close open else close it

InputMethodManager m=(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

m.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);

get input method status

InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);

boolean isOpen=imm.isActive(); isOpen if opened return true, else false

评论

此博客中的热门博文

How to change ViewPager scroll animation duration and velocity

When you call change current selected view pager position you may call like this. // change current position default is viewPager.setCurrentItem(position, true); viewPager . setCurrentItem ( position ); There will show transaction animation for change position , but this animation is too fast. So I want change this animation. When I see source code I find this, like flow. where is the scroll animation and speed.     int duration = 0 ;     velocity = Math . abs ( velocity );     if ( velocity > 0 ) {         duration = 4 * Math . round ( 1000 * Math . abs ( distance / velocity ));     } else {         final float pageWidth = width * mAdapter . getPageWidth ( mCurItem );         final float pageDelta = ( float ) Math . abs ( dx ) / ( pageWidth + mPageMargin );         duration = ( int ) (( pageDelta + 1 ) * 100 ); ...

How to close SearchView in android with ActionbarSherlock or android ActionBar

How to close SearchView in android with ActionbarSherlock or android ActionBar When I use a search view for search something in android action bar; u must have create a menu for actionview( SearchView) @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.news_post_list, menu); mSearchView = (SearchView) menu.findItem(R.id.item_search).getActionView(); mSearchView.setQueryHint(getString(R.string.search_hint_news)); mSearchView.setOnQueryTextListener(this); super.onCreateOptionsMenu(menu, inflater); } and menu xml is : <menu xmlns:android="http://schemas.android.com/apk/res/android" > <item android:id="@+id/item_search" android:icon="@drawable/ic_action_search" android:title="@string/search_hint" android:showAsAction="ifRoom" android:actionViewClass="com.actionbarsherlock.widget.SearchView"/> <item android:id...

How to make ViewPager auto play with a simple recursion function in android

Today a new request for ViewPager, will set ViewPager auto play, in last code is user Handler, but I want a new way to finish it. private void autoPlay (ViewPager viewPager ) {     viewPager . postDelayed ( new Runnable () {         @Override         public void run () {             try {                 if ( adapter != null && viewPager.getAdapter() . getCount () > 0 ) {                     int position = currentCount % adapter . getCount ();                     currentCount ++;                     viewPager . setCurrentItem ( position );                     autoPlay ( viewPager);             ...