Android的appcompat工具栏伸展时搜索查看获得焦点 [英] Android appcompat toolbar stretches when searchview gets focus

查看:300
本文介绍了Android的appcompat工具栏伸展时搜索查看获得焦点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我更新的应用程序来使用常规的动作条工具栏代替。 在我的应用程序,用户必须能够选择自己的联系人列表中的联系人。要做到这一点,我添加了一个搜索查看菜单。 触点已经在列表中;在搜索查看用于使用过滤列表中的<一个href="https://developer.android.com/reference/android/widget/ArrayAdapter.html#getFilter()"><$c$c>ArrayAdapter.getFilter()方法。

I'm updating an app to use the new Toolbar instead of the regular ActionBar. In my app the user must be able to select a contact from their contact list. To do so, I've added a SearchView to the menu. The contacts are already in the list; the SearchView is used to filter the list using the ArrayAdapter.getFilter() method.

这一切都工作得很好用动作条,而工具栏的身高被拉长键盘仅落后。从Android设备监视器使用XML检查,我可以看到的ListView 背后存在我的键盘。

It all worked fine using the ActionBar, but the Toolbar's height gets stretched to just behind the keyboard. Using the XML inspection from Android Device Monitor I can see the ListView exists behind my keyboard.

它几乎好像在搜索查看要显示的建议,但我已经配置没有这样的事情。任何想法是怎么回事?

It almost seems as if the SearchView wants to display suggestions, but I have no such thing configured. Any idea what's going wrong?

图像说明问题。他们显示正常,扩大和聚焦状态搜索查看

The images illustrate the problem. They show the normal, expanded and focused state of the SearchView.

这是我的XML菜单:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <item android:id="@+id/action_forwarding_contact_search"
        app:showAsAction="always"
        android:title="@string/forwarding_contact_search"
        app:actionViewClass="android.support.v7.widget.SearchView"
        android:icon="@drawable/abc_ic_search_api_mtrl_alpha"/>
</menu>

修改 给工具栏固定高度并不能解决问题,因为它会使搜索查看消失时,它具有焦点。更改任何一个项目的重心似乎已经没有影响了搜索查看

Edit Giving the Toolbar a fixed height doesn't solve the problem, because it will make SearchView disappear when it has focus. Changing the gravity of either item seems to have no effect on the SearchView.

推荐答案

好吧,我理解了它。有与搜索查看,因为同样的事情发生与普通的EditText ■哪些是正常的布局XML放在里面没什么问题。该工具栏不是问题或者。

Ok, I figured it out. There was no problem with the SearchView, because the same happened with ordinary EditTexts which were placed normally inside a layout xml. The Toolbar wasn't the problem either.

我创建了一个空的活动,并与任何我在我的应用程序改变打得四处终于来到了我的主题。在奇巧,后来我只好&LT;项目名称=机器人:windowTranslucentStatus&GT;真&LT; /项目&GT; 的主题设定,所以导航抽屉似乎背后的地位吧。

I created an empty activity and played around with anything I changed in my app and finally came to my theme. On KitKat and later I had <item name="android:windowTranslucentStatus">true</item> set on the theme, so the navigation drawer would appear behind the status bar.

禁用/删除这样就解决了问题。这提醒 Android的我:fitsSystemWindows =真正的属性。它被设置在工具栏,而不是在主要活动的布局XML包含 DrawerLayout 。 我猜 DrawerLayout 设置自身以适应系统的窗口。 例如。有没有 fitSystemWindows 物业位置:

Disabling/removing this would resolve the issue. This reminded me of the android:fitsSystemWindows="true" property. It is set on the Toolbar, but not in the layout xml of the main activity that contains the DrawerLayout. I guess the DrawerLayout sets itself to fit the system windows. E.g. there's no fitSystemWindows property here:

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".DashboardActivity">

在哪里发生问题没有一个 NavigationDrawer ,这是一个新的活动的活动。设置机器人:fitsSystemWindows =真正的活动的布局的根节点使事情做工精细

The activity where the problem occurred did not have a NavigationDrawer, it was a new activity. Setting android:fitsSystemWindows="true" on the root node of the layout of the activity made things work fine.

因此​​,对于任何人阅读这样的:如果你有&LT;项目名称=机器人:windowTranslucentStatus&GT;真&LT; /项目&GT; 在你的主题,确保包含一个工具栏的任何根节点包含了一个机器人:fitsSystemWindows =真正的

So, for anyone to read this: if you have <item name="android:windowTranslucentStatus">true</item> in your theme, make sure any root node containing a toolbar contains a android:fitsSystemWindows="true".

工作示例:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:orientation="vertical">

    <include layout="@layout/toolbar" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <EditText
                android:id="@+id/editText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:singleLine="true" />

            <Button
                android:id="@+id/button2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="New Button" />
        </LinearLayout>
</LinearLayout>

这篇关于Android的appcompat工具栏伸展时搜索查看获得焦点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆