Xenolion
Xenolion

Reputation: 12715

Setting up Search in the Toolbar Support Action Bar doesn't work why?

I have been trying to add/create a Search functionality for my app! So after passing android documentation there was training on how to do that! I added it as it was explained but It doesn't work when I click on the search icon It doesn't respond and I can't even put any text to be searched! I am using support version 25.

    <android.support.design.widget.CoordinatorLayout 
          xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:app="http://schemas.android.com/apk/res-auto"
          android:layout_width="match_parent"
          android:layout_height="match_parent">

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

              <android.support.v4.widget.NestedScrollView
              android:id="@+id/myScrollingContent"
              android:layout_width="match_parent"
              android:layout_height="match_parent">

                    <FrameLayout
                        android:id="@+id/contentContainer"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_above="@+id/bottom_bar" />

            </android.support.v4.widget.NestedScrollView>

            <com.roughike.bottombar.BottomBar
              android:id="@+id/bottom_bar"
              android:layout_width="match_parent"
              android:layout_height="60dp"
              android:layout_gravity="bottom"
              app:bb_tabXmlResource="@xml/bottombar_tabs_three"
              app:bb_behavior="shy"/>

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

Upvotes: 0

Views: 78

Answers (2)

Xenolion
Xenolion

Reputation: 12715

After a struggle I realized,the error was caused of wrapping of Views in the Coordinator Layout. So the clicking of Toolbar was not felt it was taken up by other Views added after it. So I could change layout attributes but I decided to use Relative Layout instead.

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        xmlns:app="http://schemas.android.com/apk/res-auto">

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

            <FrameLayout
                android:id="@+id/contentContainer"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_above="@+id/bottom_bar" />

            <com.roughike.bottombar.BottomBar
                android:id="@+id/bottom_bar"
                android:layout_width="match_parent"
                android:layout_height="60dp"
                android:layout_gravity="bottom"
                android:layout_alignParentBottom="true"
                app:bb_tabXmlResource="@xml/bottom_bar_tabs" />

    </RelativeLayout> 

Upvotes: 1

Yunus Kulyyev
Yunus Kulyyev

Reputation: 1022

Try using the query listener. It detects any input that was made in the searchview

SearchView simpleSearchView = (SearchView) findViewById(R.id.simpleSearchView);
            simpleSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
                @Override
                public boolean onQueryTextSubmit(String query) {
                    //searchedInput will be the text that was entered
                    String searchedInput = query;
                    //Toast.makeText(MainActivity.this, query, Toast.LENGTH_SHORT).show();
                    return true;
                }

                @Override
                public boolean onQueryTextChange(String newText) {

                    return false;
                }
            });

Upvotes: 0

Related Questions