在 API 23 及更低版本的搜索栏上显示刻度标记,可以通过自定义搜索栏的样式和布局来实现。以下是一种可能的解决方案:
<style name="CustomSearchView" parent="Widget.AppCompat.SearchView">
<item name="queryBackground">@drawable/custom_searchview_background</item>
<item name="searchHintIcon">@drawable/custom_searchview_hint_icon</item>
<item name="searchIcon">@drawable/custom_searchview_search_icon</item>
<item name="closeIcon">@drawable/custom_searchview_close_icon</item>
<item name="searchDropdownBackground">@drawable/custom_searchview_dropdown_background</item>
<item name="searchViewStyle">@style/Widget.AppCompat.SearchView</item>
</style>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFFFFF" />
<corners android:radius="4dp" />
<stroke
android:width="1dp"
android:color="#CCCCCC" />
</shape>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#888888"
android:pathData="M19,17.6l-4.6,-4.6C14.4,12.1 15,10.7 15,9.2C15,5.4 12.6,3 9.2,3C5.4,3 3,5.4 3,9.2C3,12.6 5.4,15 9.2,15c1.5,0 2.9,-0.6 3.9,-1.6l4.6,4.6l1.4,-1.4zM9.2,13C6.2,13 4,10.8 4,7.8C4,4.8 6.2,2.6 9.2,2.6C12.2,2.6 14.4,4.8 14.4,7.8C14.4,10.8 12.2,13 9.2,13z" />
</vector>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#888888"
android:pathData="M15.5,14h-0.8l-0.3,-0.3C15.1,12.8 15.6,11.5 15.6,10C15.6,6.7 13.3,4.4 10,4.4C6.7,4.4 4.4,6.7 4.4,10C4.4,13.3 6.7,15.6 10,15.6C11.5,15.6 12.8,15.1 13.7,14.4l0.3,0.3v0.8L18,19.2l1.2,-1.2L15.5,14zM10,14C7.2,14 5,11.8 5,9C5,6.2 7.2,4 10,4C12.8,4 15,6.2 15,9C15,11.8 12.8,14 10,14z" />
</vector>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#888888"
android:pathData="M19,6.4L17.6,5L12,10.6L6.4,5L5,6.4l5.6,5.6L5,17.6L6.4,19l5.6,-5.6l5.6,5.6L19,17.6L13.4,12L19,6.4zM12,2C6.5,2 2,6.5 2,12s4.5,10 10,10s10,-4.5 10,-10S17.5,2 12,2z" />
</vector>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFFFFF" />
<corners android:radius="4dp" />
<stroke
android:width="1dp"
android:color="#CCCCCC" />
</shape>
<androidx.appcompat.widget.SearchView
android:id="@+id/searchView"
style="@style/CustomSearchView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
SearchView searchView = findViewById(R.id.searchView);
searchView.setQueryHint("Search");
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
// 处理搜索提交事件
return true;
}
@Override
public boolean onQueryTextChange(String newText) {
// 处理搜索文本变化事件
return true;
}
});
通过以上步骤,你可以在 API 23 及更低版本的搜索栏上显示刻度标记,并且自定义搜索栏的样式和布局。请注意,这只是一种解决方案,你可以根据自己的需求进行调整和修改。
没有搜到相关的沙龙
领取专属 10元无门槛券
手把手带您无忧上云