关于输入法的弹出

Eidtext这个控件默认是你点击了它获得焦点之后就会自动地弹出软键盘,前提是你在竖屏的时候。但横盘的时候,不会自动弹出弹

出软键盘了。 

隐藏软件盘

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

imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);//开始时隐藏输入法

法二:AndroidManifet.xml中对Activity进行设置。如:android:windowSoftInputMode="stateUnchanged|adju//stPan"


手动弹出软键盘

  1. InputMethodManager im = ((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE));  
  2.         im.showSoftInput(tv, 0);  
写在某个点击事件中

  1.  public void onClick(View arg0) {  
  2.                 // TODO Auto-generated method stub  
  3.                 InputMethodManager im = ((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE));  
  4.   
  5.                 if (im.showSoftInput(tv, InputMethodManager.SHOW_FORCED)) {  
  6.                     System.out.println(" return is true fullscreenmode"  
  7.                             + im.isFullscreenMode());  
  8.                 } else {  
  9.                     System.out.println(" return is not true");  
  10.                 }
  11. };  

在AlertDialog中点击输入框可显示输入法,但是要选中输入法还得添加:
alertDialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);

官方:http://developer.android.com/reference/android/app/Dialog.html

Often you will want to have a Dialog display on top of the current input method, because there is no reason for it to accept text. You can do this by setting the WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM window flag (assuming your Dialog takes input focus, as it the default) with the following code:


为了防止弹出输入法时 把后面的背景挤变形,可以在Manifest里添加:
 
  

android:windowSoftInputMode="adjustPan|stateHidden"


发布了102 篇原创文章 · 获赞 14 · 访问量 13万+

猜你喜欢

转载自blog.csdn.net/fofu33/article/details/40623745
今日推荐