3

toolbar.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_width="match_parent"
              android:layout_height="wrap_content" xmlns:card_view="http://schemas.android.com/tools"
              android:orientation="vertical"
              xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:app="http://schemas.android.com/apk/res-auto">
    <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:background="@color/colorPrimary"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:gravity="center"
            app:theme="@style/ToolBarStyle">

        <TextView
                android:id="@+id/toolbar_title"
                style="@style/style_toolbar_textView" />

    </android.support.v7.widget.Toolbar>

    <View style="@style/style_toolbar_shadow" />
</LinearLayout>

menu_events_ppl_list.xml

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

    <item android:id="@+id/menuSearchId"
          app:showAsAction="always"
          android:icon="@drawable/search_material"
          android:title="@string/str_search"
          app:actionViewClass="android.support.v7.widget.SearchView" />
</menu>

code

/** Init On create options menu **/
    private fun initOnCreateOptionsMenu(menu: Menu) {
        val inflater: MenuInflater = menuInflater
        inflater.inflate(R.menu.menu_events_ppl_list, menu)

        val search = toolbar.menu.findItem(R.id.menuSearchId).actionView as SearchView
        search.queryHint = "Search People";
        //search.setOnQueryTextListener(this);
        search.isIconified = false
        search.maxWidth = Integer.MAX_VALUE;
    }

What I am trying to display

enter image description here

What is displaying

enter image description here

Space between back button and search view is more in android, is it possible to reduce it ?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Devrath
  • 42,072
  • 54
  • 195
  • 297

2 Answers2

3

By default, Toolbar have 16dp inset after backbutton. So, include app:contentInsetStartWithNavigation="0dp" in Toolbar, it will remove that whitespace.

<androidx.appcompat.widget.Toolbar
   ..........
   ..........
   app:contentInsetStartWithNavigation="0dp"
   ..........
   ..........
</androidx.appcompat.widget.Toolbar>

The original answer is here

Faisal Shaikh
  • 3,900
  • 5
  • 40
  • 77
-1

Change showAsAction of the menu xml. This is exactly what you are looking for.

app:showAsAction="ifRoom|collapseActionView"
Dmytro Ivanov
  • 1,260
  • 1
  • 8
  • 10