Change holo spinner text colour

谁说我不能喝 提交于 2019-12-05 04:10:05

Have you tried to accept the SpinnerItemStyle to your Theme? So all Spinners in your App would've the same style. I'm using it like this and it works:

theme.xml:

<style name="exampleTheme" parent="android:Theme.Holo.Light">
    <item name="android:spinnerItemStyle">@style/SpinnerItem_example</item>
    ...
</style>

style.xml:

<style name="SpinnerItem_example" parent="android:TextAppearance.Widget.TextView.SpinnerItem">
        <item name="android:textColor">#000000</item>
</style>

Update: Taking a deeper look into the styles.xml brought me this:

<style name="Widget.DropDownItem.Spinner">
        <item name="android:checkMark">?android:attr/listChoiceIndicatorSingle</item>
</style>

<style name="Widget.DropDownItem">
        <item name="android:textAppearance">@style/TextAppearance.Widget.DropDownItem</item>
        <item name="android:paddingStart">@dimen/dropdownitem_text_padding_left</item>
        <item name="android:paddingEnd">@dimen/dropdownitem_text_padding_right</item>
        <item name="android:gravity">center_vertical</item>
</style>

So you probably need to customize the Widget.DropDownItem and accept it in your theme.

...
<item name="dropDownItemStyle">@android:style/Widget.DropDownItem</item>
...

For customizing my application the following two links helped me a lot to understand the structure of the different views. These two files are part of the android source code. May be it helps you too.

I fixed it by calling

mArrayAdapter.setDropDownViewTheme(mActivity.getTheme());

Hope this helps someone ;)

You can access the internal TextView in code without changing any styles. This is how I handled enabling and disabling Spinners

The .getSelectedView() did not work for me. So I tricked the Spinner to "show" being disabled.

You will need to define your own colors for the "disabled" look.

For Example:

R.color.blue_text //means enabled
R.color.gray_text //means disabled

So to disable my spinner:

((TextView)mySpinner.getChildAt(0)).setTextColor(getResources().getColor(R.color.gray_text));
mySpinner.setEnabled(false);
mySpinner.setFocusable(false);

To enable my spinner:

((TextView)mySpinner.getChildAt(0)).setTextColor(getResources().getColor(R.color.blue_text));
mySpinner.setEnabled(true);
mySpinner.setFocusable(true);

The getChildAt(0) function allows you to access the first item in the spinner, which is what you show on the screen as a TextView.

You don't need to change styles or modify any XML. Just do this in your code, even within event methods, you should be fine.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!