[英]EditText Android Studio keyboard
我有一個問題:我點擊EdditText但鍵盤沒有出現。 我不知道如何解決問題:
et_num.setText (et_num.getText());
et_num.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
et_num= (EditText) findViewById(R.id.et_num);
et_num.requestFocus();
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(et_num, InputMethodManager.SHOW_IMPLICIT);
//InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
return false;
};
});
這可能是關注EditText的問題。 只需在app xml布局文件中的EditText之后添加<RequestFocus />
。
例:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/et_num"
android:hint="0"
android:inputType="number"
android:focusableInTouchMode="true"
android:focusable="true" />
<requestFocus />
另外正如@cyroxis所說,如果您正在使用帶鍵盤的模擬器,您必須配置設備的設置以使用軟件,在Api 23自定義手機中只需在屏幕上兩次選項卡就會顯示一個圖標,只需觸摸即可將出現軟鍵盤。
此外,您可以創建一個公共方法來隱藏失去焦點的鍵盤。
public void hide_board()
{
InputMethodManager im=(InputMethodManager)this.getSystemService(Context.INPUT_METHOD_SERVICE);
im.hideSoftInputFromWindow(b_calcula.getWindowToken(), 0);
}
希望能幫助到你。
使鍵盤可見
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
或者你也可以在清單中設置
android:windowSoftInputMode="stateAlwaysVisible"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.