V
V
Vadim Popov2018-07-13 15:39:05
Android
Vadim Popov, 2018-07-13 15:39:05

Why does the search view in the appBar not work correctly?

Good afternoon everyone, there is a markup of the following structure

> -- CoordinatorLayout
> ----AppBarLayout
> ------SearchView
> ----NestedScrollView
> ------ListView

Screenshots from the studio, for greater clarity
5b489d06c523c329816589.png5b489d13d101a291754344.png
After clicking on the search icon in the SearchView, the input text is not displayed, I assume that something may come from above, if I remove the ListView from the structure, then it works, but I need to add lines to the list based on the search results, it also disappears button to clear the search bar. I've attached a gif below that shows it clearly.
LogCat doesn't throw any errors.
GIF
Listing all markup
<?xml version="1.0" encoding="utf-8"?>
    <android.support.design.widget.CoordinatorLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context=".SearchActivity">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="@dimen/app_bar_height"
        android:fitsSystemWindows="true"
        android:theme="@style/AppTheme.AppBarOverlay">

        <SearchView
            android:id="@+id/search_view"
            android:layout_width="match_parent"
            android:layout_height="@dimen/search_activity_height"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            android:gravity="top" />

    </android.support.design.widget.AppBarLayout>

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

    ?xml version="1.0" encoding="utf-8"?>
    <android.support.v4.widget.NestedScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context=".SearchActivity"
    android:background="@color/colorPrimaryDark"
    tools:showIn="@layout/search_top">

    <ListView
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
    </android.support.v4.widget.NestedScrollView>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vadim Popov, 2018-07-20
@vadimpopov94

It turned out that the on-screen keyboard shifts the layout, the solution is to add the following attributes to the listView

android:focusableInTouchMode="false"
android:isScrollContainer="false"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question