Search code examples
androidandroid-toolbar

SearchView show not well


I use the ToolsBar that make the Actionbar, and add a SearchView in menu. But not show well, the “Search” Text multi-line. If theres a way move the Search when i press the search close button.

picture


Solution

  • I solved myself, custom SearchView use this:

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/tools"
        android:id="@+id/main_toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        android:elevation="@dimen/default_elevation">
    
        <ImageView
            android:id="@+id/main_toolbar_logo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dip"
            android:visibility="gone" />
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
    
            <TextView
                android:id="@+id/main_toolbar_title"
                android:name="@string/app_name"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="@color/tools_bar_title_color"
                android:textSize="@dimen/text_size_large" />
    
            <RelativeLayout
                android:id="@+id/main_toolbar_search_root"
                android:layout_width="0dip"
                android:layout_height="60dp"
                android:layout_weight="1"
                android:layout_marginRight="10dip">
    
                <EditText
                    android:id="@+id/main_toolbar_search_et"
                    android:layout_width="match_parent"
                    android:layout_height="40dip"
                    android:layout_centerVertical="true"
                    android:layout_marginBottom="5dip"
                    android:layout_marginTop="5dip"
                    android:background="@drawable/custom_search_actionbar_white_bg"
                    android:hint="Enter Keywords"
                    android:imeOptions="actionSearch"
                    android:inputType="text"
                    android:paddingLeft="5dip"
                    android:singleLine="true"
                    android:textColor="@color/white"
                    android:textColorHint="@color/white"
                    android:textSize="@dimen/text_size_medium" />
    
    
                <ImageView
                    android:id="@+id/main_toolbar_search_action"
                    android:layout_width="20dip"
                    android:layout_height="20dip"
                    android:layout_alignParentRight="true"
                    android:layout_centerVertical="true"
                    android:src="@drawable/ic_search_white" />
    
                <ImageView
                    android:id="@+id/main_toolbar_search_clean"
                    android:layout_width="20dip"
                    android:layout_height="20dp"
                    android:layout_alignParentRight="true"
                    android:layout_centerVertical="true"
                    android:src="@drawable/ic_white_close"
                    android:visibility="gone" />
    
            </RelativeLayout>
    
        </LinearLayout>
    
    </android.support.v7.widget.Toolbar>