如何解决Android:在 SearchView 小部件中进行自定义
我想更改搜索图标的颜色,但无法做到。有人可以建议我怎么做吗?
这是我正在使用的代码:
<SearchView
android:id="@+id/scheme_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Type Scheme Name"
android:elevation="0dp"
android:iconifiedByDefault="false"
android:layout_gravity="left"
android:gravity="left"
app:searchHintIcon="@drawable/pluswhite">
</SearchView>
使用这个我得到以下输出:
我想将搜索图标和分隔线的颜色设为白色。
解决方法
您可以使用自定义可绘制对象,因此它可以是您需要的任何颜色:
<SearchView
..
android:searchIcon="@drawable/customIcon">
..
</SearchView>
在这种情况下,线条的颜色将为白色,只需更改 id
private void customizeSearchView() {
int searchTextId = getResources().getIdentifier("android:id/search_src_text",null,null);
EditText searchBox = ((EditText) searchView.findViewById(searchTextId));
searchBox.setBackgroundColor(Color.WHITE);
searchBox.getLayoutParams().height = LinearLayout.LayoutParams.MATCH_PARENT;
int search_plateId = getResources().getIdentifier("android:id/search_plate",null);
View mSearchPlate = ((View) searchView.findViewById(search_plateId));
mSearchPlate.setBackgroundColor(Color.WHITE);
int searchCloseImageId = getResources().getIdentifier("android:id/search_close_btn",null);
ImageView searchClose = ((ImageView) searchView.findViewById(searchCloseImageId));// change color
searchClose.setBackgroundColor(Color.WHITE);
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。