我想在我的布局中使用SearchView(不是放在ToolBar或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>
我正在使用AppCompat,但在Android 5.0以下的设备上显示效果不同。EditText控件在这些设备上缺少底部边框。
Android 5.0及以上版本的搜索框能够正确地显示底部边框:
![Lollipop SearchView with bottom border](https://istack.dev59.com/aRNYl.webp)
![Pre-lollipop SearchView with NO bottom border](https://istack.dev59.com/uiijC.webp)
<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>
任何帮助使我的样式保持一致都将不胜感激,谢谢。