2010-11-18 147 views

回答

6

您是否尝试将android:configChanges =“keyboard | keyboardHidden”添加到您的活动中?

例如为:

<activity android:name=".MyApp" android:label="@string/app_name" android:configChanges="keyboard|keyboardHidden"> 

它是否适用于屏幕键盘以及物理上的不知道。

您也可以乱用使用InputMethodManager的屏幕键盘,例如隐藏它,你可以使用:

InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); 
imm.hideSoftInputFromWindow(mCurretnView.getWindowToken(), 0); 
+0

感谢您的帮助。我已经尝试过,但它不工作。 – Tester 2010-11-18 14:41:39

3

正如this question使用:

EditText edtView=(EditText)findViewById(R.id.editTextConvertValue); 
edtView.setInputType(0); 
1
InputMethodManager inputMethodManager = (InputMethodManager) currentActivity.getSystemService(Context.INPUT_METHOD_SERVICE); 
if (isShow) { 
    if (currentActivity.getCurrentFocus() == null) { 
     inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); 
    } else { 
     inputMethodManager.showSoftInput(currentActivity.getCurrentFocus(), InputMethodManager.SHOW_FORCED);  
    } 

} else { 
    if (currentActivity.getCurrentFocus() == null) { 
     inputMethodManager.toggleSoftInput(InputMethodManager.HIDE_NOT_ALWAYS, 0); 
    } else { 
     inputMethodManager.hideSoftInputFromInputMethod(currentActivity.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);  
    } 

} 
0

试试这个

@Override 
public boolean dispatchTouchEvent(MotionEvent event) { 
    boolean ret = super.dispatchTouchEvent(event); 
    InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); 
    imm.hideSoftInputFromWindow(mCurretnView.getWindowToken(), 0); 
    return ret; 
} 

editText.setOnTouchListener(new View.OnTouchListener() { 

    @Override 
    public boolean onTouch(View v, MotionEvent event) { 
     InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); 
     imm.hideSoftInputFromWindow(mCurretnView.getWindowToken(), 0); 
     return false; 
    } 
});