Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change border color of a SearchView

I want to change a border color of my searchview . Right now its coming transparent . I tried giving styling to it but nothing working .

SearchView.xml

 <LinearLayout
        android:id="@+id/linear1"
        android:background="@android:color/white"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:weightSum="1">

    <android.support.v7.widget.SearchView
        android:layout_width="300dp"
        android:layout_height="wrap_content"
        android:id="@+id/searchView"
        android:background="@android:color/white"
        android:layout_marginTop="10dp"
        style="@style/CitySearchView"
        android:layout_weight="0.9"
        android:layout_marginLeft="10dp"/>

style.xml

<style name="CitySearchView" parent="Widget.AppCompat.Light.SearchView">
        <item name="searchIcon">@drawable/blue_search_bar</item>
        <item name="colorControlActivated">@color/labelColorHighligh</item>
        <item name="colorControlNormal">@color/backgroud_user</item>
        <item name="queryBackground">@color/labelColorHighligh</item>

    </style>
like image 401
young_08 Avatar asked Apr 27 '16 11:04

young_08


1 Answers

  1. Create drawable file background.xml with this content:

    <?xml version="1.0" encoding="UTF-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:padding="12dp"
        android:shape="rectangle" >
        <solid android:color="#FFFFFF" />
        <stroke
            android:width="0.3dp"
            android:color="#797979" />
    </shape>     
    
  2. Add the drawable to the background:

    <android.support.v7.widget.SearchView
        android:background="@drawable/background"
        android:id="@+id/searchView"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:layout_width="300dp" />
    
like image 144
Rohit Rathore Avatar answered Sep 19 '22 02:09

Rohit Rathore