我一直在尝试更改 Spinner TextView 的颜色。我需要以编程方式进行。我有我的个人适配器和资源 View 。 (我不想更改弹出的 sipnner 文本颜色,只有选择 somenthig 时显示在用户布局上的文本)
这是我的代码:
PersonalArrayAdapter spAdapterInfraccion = new PersonalArrayAdapter(getContext(),
R.layout.item_spinner,
infraccionList);
spinner.setAdapter(spAdapter);
item_spinner.xml:
<?xml version="1.0" encoding="utf-8"?>
<co.my.app.utils.CustomTextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceListItemSmall"
android:gravity="center_vertical"
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
android:minHeight="?android:attr/listPreferredItemHeightSmall" />
这是我尝试过的方式,但返回 null。
CustomTextView text = (CustomTextView)view.findViewById(R.id.text1);
text.setTextColor(getContext().getColor( R.color.black ));
最佳答案
你可以试试这个:-
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
int index = adapterView.getSelectedItemPosition();
((TextView) spinner.getSelectedView()).setTextColor(getResources().getColor(R.color.Blue));
希望对您有所帮助。 :)
关于Android 改变 Spinner 的 TextView 颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43233347/