0

I have a searchView in the Toolbar which also has Gridview elements. Everything works fine except the queryHint doesn't get displayed in the searchView. I have tried setting android:iconifiedByDefault="false" but the issue persists. Below is the code of activity's layout.

firstscreen.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    tools:context=".ui.activities.FirstScreen">

    <!-- android:numColumns=2 is the number of columns for Grid View
         android:horizontalSpacing is the space between horizontal grid items -->
    <androidx.fragment.app.FragmentContainerView
        android:id="@+id/nav_host_fragment"
        android:name="androidx.navigation.fragment.NavHostFragment"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toTopOf="@id/bottomNavigationView"
        app:defaultNavHost="true"
        app:navGraph="@navigation/nav_graph" />

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:background="@color/bottomNavigation"
        android:id="@+id/bottomNavigationView"
        android:layout_width="match_parent"
        android:layout_height="66dp"
        app:layout_insetEdge="bottom"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"
        app:menu="@menu/bottom_navigation_menu"/>
</androidx.constraintlayout.widget.ConstraintLayout>

And this is my fragment's xml layout where the searchview is added. fragment_user.xml

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

    <!-- Add the Toolbar -->
    <androidx.appcompat.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/flash_tablebar"
        android:title="Lingo"
        android:titleTextColor="@color/new_design_darker_shade">

        <androidx.appcompat.widget.SearchView
            android:id="@+id/searchView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="50dp"
            android:layout_marginEnd="40dp"
            android:layout_marginTop="20dp"
            android:layout_marginBottom="10dp"
            android:background="#FFFF"
            android:queryHint="Search..."
            android:textColorHint="@android:color/black"
            android:iconifiedByDefault="false"/>
    </androidx.appcompat.widget.Toolbar>

    <!-- NestedScrollView to contain the GridView and make it scrollable -->
    <androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:fillViewport="true">

        <!-- Your GridView -->
        <GridView
            android:id="@+id/mainSpecimens"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="?android:actionBarSize"
            android:clipToPadding="false"
            android:horizontalSpacing="6dp"
            android:numColumns="3"
            android:verticalSpacing="6dp" />
    </androidx.core.widget.NestedScrollView>
</LinearLayout>

1 Answer 1

1

you should change tag of queryHint and iconifiedByDefault form android to app.

app:queryHint="Search..."

app:iconifiedByDefault="false"

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.