Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android AppCompat SearchView EditText missing bottom line on pre-lollipop

I am trying to use a SearchView in my layout (not inside of a ToolBar or ActionBar).

<FrameLayout android:layout_width="0dp" android:layout_weight="50" android:layout_height="wrap_content" >
    <android.support.v7.widget.SearchView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom|left" style="@style/MySearchViewStyle" />
  </FrameLayout>

I am using AppCompat, but it looks different on pre-lollipop. The EditText is missing the bottom border in pre-lollipop devices.

Lollipop Search displays border correctly: Lollipop SearchView with bottom border

Pre-lollipop Search displays NO border: Pre-lollipop SearchView with NO bottom border

My theme is basic:

    <style name="Theme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- TOOLBAR -->
     <item name="android:windowNoTitle">true</item>
     <item name="windowActionBar">false</item>
     <item name="windowNoTitle">true</item>
     <!-- Search -->
     <item name="searchViewStyle">@style/MySearchViewStyle</item>
     <item name="android:searchViewStyle">@style/MySearchViewStyle</item>
     <!-- COLOURS -->
     <item name="colorPrimary">@color/primary</item>
     <item name="colorPrimaryDark">@color/primary_dark</item>
     <item name="colorAccent">@color/accent</item>
  </style>
  <style name="MySearchViewStyle" parent="Widget.AppCompat.SearchView">
     <item name="android:editTextStyle">@style/EditText</item>
     <item name="editTextStyle">@style/EditText</item>
  </style>
  <style name="EditText">
    <item name="android:layout_height">wrap_content</item>
    <item name="android:layout_width">wrap_content</item>
    <item name="android:inputType">text</item>
    <item name="android:cursorVisible">true</item>
    <item name="android:maxLength">1000</item>
    <item name="android:selectAllOnFocus">true</item>
    <item name="android:paddingTop">4dp</item>
  </style>

Any help to get my styles consistent would be great thanks.

like image 968
Daisy Avatar asked Jun 29 '15 13:06

Daisy


1 Answers

As per Source code at https://github.com/android/platform_frameworks_support/blob/master/v7/appcompat/res/layout/abc_search_view.xml

search_src_text view has background set to @null

To get bottom line i used

searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text).setBackgroundResource(R.drawable.abc_textfield_search_default_mtrl_alpha);
like image 134
Piyush Kukadiya Avatar answered Nov 03 '22 06:11

Piyush Kukadiya