Uninstall Android SearchView add-ons when expanding

I am trying to implement SearchView in my Android application, but an extension is added when it is expanded.

SearchView is integrated into the menu, and when the application starts, I have a search icon in the toolbar. When I click the search button, SearchView expands, but has an additional addition.

Here are a few photos so you can understand the problem:

This is the initial toolbar. Initial toolbar

When I click the search icon, this is what I get Advanced Search

I found one solution to add negative left padding (-16dp) in SearchView: searchView.setPadding(getResources().getDimensionPixelSize(R.dimen.search_view_minus), 0, 0, 0);

Unfortunately, if I use this solution, the search icon on the right side of the toolbar will be distorted (somehow, the SearchView gets the search icon).

This is my menu:

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context=".MainActivity">

    <item
        android:id="@+id/action_search"
        android:icon="@drawable/ic_search_white_48dp"
        app:showAsAction="always"
        app:actionViewClass="android.support.v7.widget.SearchView"
        android:title="Cauta..."/>

</menu>

:

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar_home"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="@color/colorPrimary"
    app:theme="@style/AppTheme.Title"
    app:titleMarginStart="0dp"
    app:navigationIcon="@drawable/ic_menu_white_24dp"
    app:contentInsetStartWithNavigation="0dp"
    app:contentInsetEndWithActions="0dp"
    app:contentInsetStart="0dp"
    app:contentInsetEnd="0dp" />

, SearchView:

<style name="searchStyle" parent="Widget.AppCompat.SearchView.ActionBar">
    <item name="queryHint">@string/search_hint</item>
    <item name="searchIcon">@drawable/ic_search_white_24dp</item>
    <item name="voiceIcon">@drawable/ic_keyboard_voice_white_24dp</item>
    <item name="android:textColorHint">@android:color/white</item>
</style>

?

+6

Source: https://habr.com/ru/post/1015084/


All Articles