【发布时间】:2023-04-03 07:05:01
【问题描述】:
我在自定义 xml 布局中有一个 EditText,它在 EditTextPreference 中动态加载(setView)。一切正常。现在,当单击首选项并显示 editPreference 对话框时,软键盘也会显示。我不希望软键盘默认显示!
这是我尝试过的。应该工作:(!
public class ReportBugPreference extends EditTextPreference {
@Override
protected void onPrepareDialogBuilder(AlertDialog.Builder builder) {
super.onPrepareDialogBuilder(builder);
View viewBugReport = LayoutInflater.from(ctx).inflate(R.layout.preference_report_bug,null);
builder.setView(viewBugReport);
EditText edttxtBugDesc = (EditText) viewBugReport.findViewById(R.id.bug_description_edittext);
//edttxtBugDesc.clearFocus();
InputMethodManager inputManager = (InputMethodManager) ctx.getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(edttxtBugDesc.getApplicationWindowToken(), 0);
}
}
【问题讨论】:
-
你的意思是当用户点击 EditText 时软键盘会显示 ?am i right?
-
不! EditText 默认有焦点,因此软键盘会自动显示
-
所以你不希望软键盘默认打开。
-
您没有在 XML 文件中尝试
android:focusable属性和android:focusableInTouchMode吗?如果我正确理解了这个问题,我认为您可以通过 XML 文件而不是硬编码来实现您想要的。
标签: android android-edittext android-softkeyboard preferenceactivity