我有一个Spinner并使用ArrayAdapter.在适配器中我使用“android.R.layout.simple_list_item_1”,如下所示:
spinnerControlObjectType.setAdapter(new ArrayAdapter(getApplicationContext, android.R.layout.simple_list_item_1, list))
我查看了android.R.layout.simple_list_item_1并看到它有这样的文本样式:
机器人:textAppearance = “机器人:ATTR / textAppearanceListItemSmall”
我想在我的主题中覆盖“textAppearanceListItemSmall”以赋予它不同的颜色,我该怎么做?我不想继承任何东西或编写代码样板.我确信有一种方法可以改变颜色,只更改theme.xml.
解决方法:
为您的微调器项创建自定义XML文件
spinner_layout.xml
添加自定义颜色
android:id="@+id/custom_spinner"
android:textSize="16sp"
android:text="HELLO"
android:padding="10dp"
android:textColor="@color/colorAccent"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
使用此文件显示您的微调器项目
ArrayAdapter adapter = new ArrayAdapter(MainActivity.this, R.layout.spinner_layout,ar);
mSpinner.setAdapter(adapter);
标签:android,colors,styles,themes,spinner
来源: https://codeday.me/bug/20190715/1465712.html