android:spinner提示符未在API中显示> 23

时间:2017-04-07 00:02:24

标签: java android android-spinner

我正在制作一个Android应用程序,我在对话模式下使用Spinners,定义如下:

<Spinner android:id="@+id/new_order_address"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:theme="@style/SpinnerTheme"
     style="@style/UnderlinedSpinner"
     android:layout_below="@+id/new_order_hint_address"
     android:prompt="@string/myString"
     android:spinnerMode="dialog"
     android:layout_marginBottom="5dp" />

样式

<style name="SpinnerTheme">
    <item name="colorControlNormal"> @color/colorPrimaryDark </item>
    <item name="android:textColorSecondary"> @color/colorPrimaryDark </item>
    <item name="android:colorControlHighlight"> @color/colorPrimaryDark </item>
    <item name="android:colorControlActivated"> @color/colorPrimaryDark </item>
    <item name="android:minHeight"> 35dp </item>
    <item name="android:showDividers"> middle </item>
    <item name="android:divider"> @color/colorAccent </item>
    <item name="android:dividerHeight"> 0.5dp </item>
</style>

<style name="SpinnerLabel" parent="TextAppearance.Design.Hint">
    <item name="android:paddingLeft">@dimen/input_label_horizontal_spacing</item>
    <item name="android:paddingRight">@dimen/input_label_horizontal_spacing</item>
    <item name="android:textSize"> 14sp </item>
    <item name="android:textColor">@color/hintText</item>
</style>

<style name="UnderlinedSpinner" parent="Base.Widget.AppCompat.Spinner.Underlined"/>

在API&lt; 23中,一切正常,但在API 23中,未显示提示。我尝试过使用java代码,我已经阅读了所有类似的问题和答案,并且没有任何运气。

提前致谢

1 个答案:

答案 0 :(得分:0)

Ok, after a lot more of trial and error, I found out that the issue was in fact that the color of the prompt text was the same as the color of the background of the prompt (both white).

The reason behind it relays on the "textColorPrimary", which I'm not setting in the style of the spinner, but I did set in the style of the Tabhost where it is located. It looks like it inherited this property.

Therefore, the solution is just adding that parameter to the style, with the color desired.

The only thing I'm not sure is why this only happens in APIs > 23, and not the others.