Search code examples
androidandroid-constraintlayoutsearchview

Android - SearchView top of ImageView not showing for API > 21


<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
    tools:context=".MainActivity">

    <RelativeLayout
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHeight_default="percent"
        app:layout_constraintHeight_percent="0.4"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:elevation="5dp"
        android:translationZ="5dp">
        <ImageView
            android:id="@+id/imageView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:contentDescription="Book"
            android:src="@drawable/bookbackground"
            android:layout_centerInParent="true"
            android:scaleType="centerCrop"
            />
        <SearchView
            android:id="@+id/books"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Search Books"
            android:layout_marginRight="30dp"
            android:layout_marginLeft="30dp"
            android:elevation="5dp"
            android:translationZ="5dp"
            android:layout_centerInParent="true"

            />

    </RelativeLayout>




<!--https://pixabay.com/photos/books-students-library-university-1281581/ -->
</androidx.constraintlayout.widget.ConstraintLayout>

enter image description here


Solution

  • try to set background to searchview you will surely get your searchview seen... or go for custom searchview so that it can seen

    <?xml version="1.0" encoding="utf-8"?>
    <androidx.constraintlayout.widget.ConstraintLayout 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"
    tools:context=".MainActivity">
    
    <RelativeLayout
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHeight_default="percent"
        app:layout_constraintHeight_percent="0.4"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:elevation="5dp"
        android:translationZ="5dp">
        <ImageView
            android:id="@+id/imageView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:contentDescription="Book"
            android:src="@drawable/bookbackground"
            android:layout_centerInParent="true"
            android:scaleType="centerCrop"
            />
        <SearchView
            android:id="@+id/books"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Search Books"
            android:layout_marginRight="30dp"
            android:layout_marginLeft="30dp"
            android:elevation="5dp"
            android:translationZ="5dp"
            android:background:"your color"
            android:layout_centerInParent="true"
    
            />
    
    </RelativeLayout>
    
    
    
    
      <!--https://pixabay.com/photos/books-students-library-university-1281581/ -->
        </androidx.constraintlayout.widget.ConstraintLayout>