Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove the Android SearchView left space?

I'm trying to remove the left space before the search view of Android, without success. I tried every answer I found on Internet but didn't work. I'm using AppCompat themes for this activity. I'm targeting KitKat api (19).

Can someone help me please? enter image description here

EDIT

Layout of activity

<?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"
android:id="@+id/MainLayout"
android:background="#6ED19E">
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/BackgroundLayout"
    android:background="#6ED19E">
    <ImageView
        android:src="@drawable/bgpattern"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/PatternImageView"
        android:scaleType="centerCrop" />
    <TextView
        android:text="Já estamos em muitas cidades\nEstamos na sua?"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/ManyCityLabel"
        android:textColor="#ffffff"
        android:textSize="25dp"
        android:width="20dp"
        android:gravity="center"
        android:textStyle="normal" />
</RelativeLayout>
<ListView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/LocationsListView"
    android:background="#ffffff"
    android:visibility="invisible" />

Menu

<?xml version="1.0" encoding="utf-8" ?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/apk/res-auto"
      android:layout_width="match_parent"
      android:layout_height="wrap_content">
  <item android:id="@+id/LocationSearch"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        tools:showAsAction="always"
        tools:actionViewClass="android.support.v7.widget.SearchView"/>
</menu>

The iconified stuff I did programatically because when I change the xml didn't work

EDIT If I set the background color of SearchView

enter image description here

The search doesn't fit the entire space. Why?

like image 947
Leandro De Mello Fagundes Avatar asked Oct 30 '22 10:10

Leandro De Mello Fagundes


1 Answers

Get output like this:

You can do following:

Hide app bar in onCreate() like so:

// Hide UI first
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
    actionBar.hide();
}

In the layout file set background to green (or your colour), add a SearchView and set background for SearchView to white like so:

<android.support.constraint.ConstraintLayout 
    ...
    android:background="#00FF00"
    ...>

    <android.support.v7.widget.SearchView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#FFF" />
    ...
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    ....
</android.support.constraint.ConstraintLayout>

I am pretty sure that your other search interface code shall work. You only need to redirect your event calls.

like image 84
BhalchandraSW Avatar answered Nov 15 '22 07:11

BhalchandraSW