Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/179.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
清除任务后未关闭android软键盘_Android_Soft Keyboard - Fatal编程技术网

清除任务后未关闭android软键盘

清除任务后未关闭android软键盘,android,soft-keyboard,Android,Soft Keyboard,在我的应用程序中,我有一个带有一个图像的edittext,用于将任务添加到数据库中。我的问题是,当我在数据库中添加任务时,android软键盘可见,而不是关闭。我正在堆栈溢出中使用所有这些示例,但没有得到结果。请任何人帮助我 <EditText android:id="@+id/edittextidAddTodayTask" android:layout_width="fill_parent" android:layout_height="wrap_content"

在我的应用程序中,我有一个带有一个图像的edittext,用于将任务添加到数据库中。我的问题是,当我在数据库中添加任务时,android软键盘可见,而不是关闭。我正在堆栈溢出中使用所有这些示例,但没有得到结果。请任何人帮助我

<EditText
    android:id="@+id/edittextidAddTodayTask"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:background="@drawable/edittextselector"
    android:drawableRight="@drawable/addtask"
    android:hint="AddTask"
    android:singleLine="true"
    />
我的edittext屏幕截图:


尝试将焦点移动到任何其他视图

然后关闭键盘

试试这个

edtText.addTextChangedListener(new TextWatcher() {

    @Override
    public void onTextChanged(CharSequence s, int start, int before,  int count) {


    }

    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {

    }

    @Override
    public void afterTextChanged(Editable s) {

InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(edittextAddTask.getWindowToken(), 0);
    }
});

我不明白,请简单介绍一下,在数据库中插入数据后,尝试隐藏“添加”按钮的“单击”事件的键盘我没有使用onclick事件,仅使用onDrawableTouch侦听器…好的…那么你是在片段中还是在活动中实现代码?我是在片段中实现的
edtText.addTextChangedListener(new TextWatcher() {

    @Override
    public void onTextChanged(CharSequence s, int start, int before,  int count) {


    }

    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {

    }

    @Override
    public void afterTextChanged(Editable s) {

InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(edittextAddTask.getWindowToken(), 0);
    }
});