【问题标题】:Get keyboard to disappear when clicking outside of searchview在搜索视图之外单击时让键盘消失
【发布时间】:2015-09-21 19:42:21
【问题描述】:

当我在搜索视图选项卡之外单击时,我目前正试图让键盘消失。

我的问题是,我尝试将 onfocus 更改侦听器附加到最顶部的布局,以便在单击外部时从 searchview 清除焦点,虽然它有效,但侦听器只能工作到略低于进度条。我无法让监听器覆盖整个屏幕。帮助?我试图获得最顶层布局的父级,但没有奏效。

这是我的屏幕图片,一直显示到听众工作的地方:https://drive.google.com/file/d/0B7Dd6tnM1aneaUVZNTI1NXQydDA/view?usp=sharing

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/session_linear_layout"
    android:orientation="vertical" >


    <SearchView
        android:id="@+id/Session_searchbar"
        android:layout_width="match_parent"
        android:layout_height="47dp"
        android:focusable="true"
        android:focusableInTouchMode="true" />

    <ProgressBar
        android:id="@+id/session_progress_spinner"
        style="?android:attr/progressBarStyleLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical|center_horizontal" >
    </ProgressBar>

</LinearLayout>

【问题讨论】:

    标签: android android-activity keyboard searchview listeners


    【解决方案1】:

    试试下面的代码

    InputMethodManager inputManager = 
            (InputMethodManager) context.
                getSystemService(Context.INPUT_METHOD_SERVICE); 
    inputManager.hideSoftInputFromWindow(
            searchView.getWindowToken(),
            InputMethodManager.HIDE_NOT_ALWAYS); 
    

    【讨论】:

    • 我现在有那个代码,我只是不知道把它放在哪里,因为把它放在父布局中,它只能在屏幕中间附近工作
    • LinearLayout 上使用OnTouchListener 并在MOVE_UP 上关闭它
    • 我已经这样做了,但是 ontouch 监听器只能在 progressBar 上工作,而不是在它下面。切科
    • 你的LinearLayout没有高度?它的高度是多少?
    猜你喜欢
    • 2019-01-31
    • 1970-01-01
    • 2018-12-31
    • 2014-07-21
    • 2011-04-13
    • 2017-10-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多