带有自定义文本字体和颜色的微调器 [英] Spinner with custom text font and color
本文介绍了带有自定义文本字体和颜色的微调器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在Spinner中使用自定义字体和颜色.我无法直接在<spinner/>
I want to use custom font and color in Spinner. I can't modify them directly in <spinner/>
这是我的代码
<Spinner
android:id="@+id/spinner2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="5pt"
android:layout_marginTop="5pt"
android:backgroundTint="#d9d9d9"
android:entries="@array/dropdown_main" />
它应该看起来像这样:
文本字体为Product Sans Bold,颜色为#333333
Text font is Product Sans Bold, color is #333333
推荐答案
在这里,您可以在布局文件夹中创建一个自定义xml文件,您可以在其中添加以下内容:
Here you can make a custom xml file in layout folder where you can add this:
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#333333"
android:padding="10dp"
android:textStyle="bold" />
然后在您的代码中像这样提及它:
And then in your code mention it like this:
val adapter = ArrayAdapter.createFromResource(this, R.array.array_name, R.layout.custom_spinner) // where array_name consists of the items to show in Spinner
adapter.setDropDownViewResource(R.layout.custom_spinner) // where custom-spinner is mycustom xml file.
然后设置适配器.
这篇关于带有自定义文本字体和颜色的微调器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文