首页 > 解决方案 > 如何在xamarin android中将自定义字体设置为searchview提示

问题描述

我在 xamarin android 中使用 searchview。我在 Assets->fonts 文件夹中有一个自定义字体。我需要将该字体应用于我的搜索视图提示。

我尝试如下:

字体类型 = Typeface.createFromAsset(getAssets(),"fonts/Kokila.ttf"); searchView.setTypeface(type);

但它不起作用。谁能告诉我如何将自定义字体应用于搜索视图提示。

谢谢

标签: androidxamarin.android

解决方案


您需要更改搜索视图内的 textview 字体。

使用该代码访问文本视图:

LinearLayout linearLayout1 = (LinearLayout)SearchView.GetChildAt(0);
LinearLayout linearLayout2 = (LinearLayout)linearLayout1.GetChildAt(2);
LinearLayout linearLayout3 = (LinearLayout)linearLayout2.GetChildAt(1);
AutoCompleteTextView textView = (AutoCompleteTextView)linearLayout3.GetChildAt(0);
textView.Typeface = YourCustomTypeface;

快乐编码!


推荐阅读