【问题标题】:Change the appearance of a Spinner in Android在 Android 中更改 Spinner 的外观
【发布时间】:2012-05-18 15:15:12
【问题描述】:

我想更改微调器的外观,使其在外部看起来像一个文本视图。我目前的做法是这样的:

 <Spinner 
     android:id="@+id/spinner"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     style="@style/spinner_style"/>

和样式资源:

 <style name="spinner_style" parent ="@android:attr/textViewStyle">
     <item name="android:layout_width">wrap_content</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:textAppearance">@style/MyText</item>

 </style>


<style name="MyText" parent="@android:style/TextAppearance">
    <item name="android:textColor">#00ffff</item>
</style>

它不会抛出任何错误,但对外观也没有影响。或者我可能会在 Textview 上绑定一个微调器,但不知道如何:)

感谢您的帮助。

【问题讨论】:

    标签: android styles spinner


    【解决方案1】:

    我认为您需要更改微调器的背景,因为这使它具有“微调器”外观(文本区域 + 箭头)。

    <item name="android:background">@android:color/transparent</item>
    

    最好使用 9-Patch 绘图来替换背景,这样您就可以正确地表示任何文本。

    【讨论】:

    • 我尝试设置 ​​@color/red,效果很好。最好将其设置为 null 以没有背景。我将如何在 XML 中做到这一点?
    • 我很困惑。如果您尝试将背景设置为红色并且效果很好,那么您为什么不保持这种状态呢?您的评论 is 使用 XML,您只是在使用样式来实现您所需要的,这是一件好事。
    • 我不希望背景是红色的,我希望它像普通的 textview 一样不可见。 ​​@color/null 不起作用,因为 null 未知 ...
    • 哦,我明白你想要什么了。您需要使用 透明 颜色。请参阅编辑后的解决方案。
    【解决方案2】:

    您必须将背景设置为空:

    <item name="android:background">@null</item>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多