I have the following layout which contains a SearchView
and i want its icon to be on the right side instead of the default left. I looked up multiple posts on here and their respective answers but none worked. Any ideas on how to do it? Is there an xml
attribute i can add or do i have to do it programatically?
<?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=".presenter.CultureActivity">
<androidx.appcompat.widget.Toolbar
android:id="@+id/culture_toolbar"
android:layout_width="match_parent"
android:layout_height="145dp"
android:background="@drawable/toolbar_gradient"
android:elevation="4dp"
android:paddingTop="40dp"
app:layout_scrollFlags="scroll|enterAlways"
app:titleTextColor="@android:color/white"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginEnd="20dp">
<TextView
android:id="@+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|top"
android:layout_marginTop="10dp"
android:fontFamily="@font/montserrat_medium"
android:text="@string/toolbar_title_placeholder"
android:textColor="@android:color/white"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.appcompat.widget.SearchView
android:id="@+id/searchBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|top"
android:layout_marginTop="5dp"
android:background="@drawable/searchbar_rounded_bg"
app:defaultQueryHint="@string/search_hint"
app:iconifiedByDefault="false"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/toolbar_title" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.appcompat.widget.Toolbar>
<!-- Implement the main layout -->
<include
android:id="@+id/shadow"
layout="@layout/navbar_shadow"
android:layout_width="match_parent"
android:layout_height="4dp"
app:layout_constraintBottom_toTopOf="@+id/bottom_nav_bar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<include
android:id="@+id/bottom_nav_bar"
layout="@layout/bottom_navbar"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Edit: Result of Sumit Shukla's answer implementation:
Expected result:
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…