如何设置SerachView背景白色和文本颜色黑色(How to set SerachView background white and text Color black)

编程入门 行业动态 更新时间:2024-10-25 12:26:49
如何设置SerachView背景白色和文本颜色黑色(How to set SerachView background white and text Color black)

我找不到任何关于Xamarin android处理SearchView的文章。

下面的searchView将提供黑色背景和白色textColor

1)我需要将背景颜色设置为白色,将textColor设置为白色。 2)如果用户决定不使用搜索,键盘就不会消失。 单击searchView后如何关闭键盘?

谢谢

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#ffffff" android:orientation="vertical"> <SearchView android:minWidth="25px" android:minHeight="25px" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#ffffff" android:id="@+id/sv" /> <ListView android:minWidth="25px" android:minHeight="25px" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/merchantListView" /> </LinearLayout>

I could not find any article on Xamarin android handling SearchView.

The searchView below will provide a black background and white textColor

1) I need to set the background color white and textColor white. 2) The keyboard wont go away if user decided not to use search. How to dismiss the keyboard after clicking the searchView?

Thanks

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#ffffff" android:orientation="vertical"> <SearchView android:minWidth="25px" android:minHeight="25px" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#ffffff" android:id="@+id/sv" /> <ListView android:minWidth="25px" android:minHeight="25px" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/merchantListView" /> </LinearLayout>

最满意答案

使用以下代码将文本颜色设置为黑色

SearchView sv = FindViewById<SearchView>(Resource.Id.sv); int id = sv.Context.Resources.GetIdentifier("android:id/search_src_text", null, null); TextView tv = (TextView)sv.FindViewById(id); tv.SetTextColor(Android.Graphics.Color.Black);

您可以单击键盘上的搜索玻璃图标以关闭它,或者在需要关闭SearchView的焦点时设置sv.ClearFoucs() 。

Use the below code to set text color to black

SearchView sv = FindViewById<SearchView>(Resource.Id.sv); int id = sv.Context.Resources.GetIdentifier("android:id/search_src_text", null, null); TextView tv = (TextView)sv.FindViewById(id); tv.SetTextColor(Android.Graphics.Color.Black);

You can click on the search glass icon in keyboard to dismiss it or set sv.ClearFoucs() whenever you need to dismiss focus for the SearchView.

更多推荐

本文发布于:2023-08-05 22:55:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1441114.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何设置   文本   白色   颜色   黑色

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!