【问题标题】:How can I change the Android spinner prompt style如何更改 Android 微调器提示样式
【发布时间】:2012-10-17 05:10:37
【问题描述】:

我已经开发了一个示例。我需要更改 Android 微调器提示的样式。如何更改样式?

这是我的 string.xml 代码:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="hello">Hello World, CustomizedListView!</string>
    <string name="app_name">CustomizedListView</string>
    <string name="status_prompt">Choose a Status</string>
</resources>

此代码用于我的main.xml

<Spinner android:id="@+id/spinner1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_x="106dp"
    android:layout_y="100dp"
    android:prompt="@string/status_prompt"
    android:background="@drawable/btn_dropdown"/>

这里我想改变下图的背景颜色和textSizetextStyle。我该如何更改?

【问题讨论】:

    标签: android android-spinner prompt


    【解决方案1】:

    如果您想创建自己的custom spinner,请参考Android: Custom spinner with custom object!

    背景:

    值/样式.xml

    <resources>
       <style name="MyTheme">
        <item name="android:spinnerStyle">@style/StandardSpinner</item>
       </style>
    </resources>
    
    <style name="StandardSpinner" parent="@android:style/Widget.Spinner">
        <item name="android:background">@drawable/spinner</item>
    </style>
    

    文字大小:

    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.planets_array, R.layout.textview);
    

    您只需更改您使用微调器的 TextView 的设计。我只是尝试了这个,作为textview.xml的布局:

    <TextView xmlns:android="http://schemas.android.com/apk/res/android"
              android:text="@+id/TextView01" android:id="@+id/TextView01"
              android:layout_width="wrap_content" 
              android:layout_height="wrap_content" 
              android:textSize="30sp"></TextView>
    

    【讨论】:

    • 我希望更改默认微调器提示背景颜色和 testSize,textStyle 的样式。这是我的提示 Choose a Status 如何更改提示样式
    • 嗨 Lokesh,我已经使用了您上面的代码。样式是更改微调器项目,只是它不会更改微调器标题文本。
    • -1:这不会更改微调器提示,这是用户要求的。相反,它会更改微调器列表项的样式。
    猜你喜欢
    • 1970-01-01
    • 2021-01-05
    • 1970-01-01
    • 1970-01-01
    • 2011-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多