【发布时间】:2020-11-04 11:57:57
【问题描述】:
我有一个按钮和一个 EditText,当我按下按钮时,光标应该出现在 EditText 中并且应该显示软键盘。我已经尝试了 SO 的一堆建议,但没有任何效果。到目前为止,这是我的逻辑:
<EditText
android:id="@+id/typed_word"
android:maxLength="10"
android:enabled="false"
android:inputType="text"
android:layout_below="@+id/word_list"
android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
android:textStyle="bold"
android:textSize="25sp"
android:textColor="@color/colorPrimaryDark"
android:layout_margin="10dp"
android:hint="@string/type_hint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
当按下按钮时,EditText 中会发生这种情况:
start_timer_button.setOnClickListener(new OnClickListener(){
public void onClick(View v)
{
InputMethodManager inputMgr = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
assert inputMgr != null;
inputMgr.showSoftInput(typed_word, InputMethodManager.SHOW_IMPLICIT);
reset_button.setEnabled(true);
typed_word.requestFocus();
word_list.setText("");
typed_word.setText("");
typed_word.setEnabled(true);
text_str = "";
start_timer_button.setEnabled(false);
enableSettings = false;
}
});
谁能看到我做错了什么?这两天我一直在纠结这个问题。
【问题讨论】:
标签: android android-edittext android-cursor