如何使用标签显示微调器(静态文本)?

Adi*_*i K 12 android spinner

我想在它上面显示带有静态小标签的微调器,它是如何可以看到一个流行的应用程序想要显示相同的.

这是我的图像,红色标记的是旋转器,上面有灰色文本,不会改变

我不想显示android:prompt哪个显示内部微调器中的默认文本想要在同一控件中的微调器上方精确显示

在此输入图像描述

Ham*_*mad 7

为此,您将必须创建自定义微调器:

微调器的布局根据您的需要命名为custom_spinner:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">

    <TextView
        android:id="@+id/tVStaticSmallLabel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="static text"
        android:textColor="#777777"
        android:textSize="22px" />

    <TextView
        android:id="@+id/tVMainText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/tVStaticSmallLabel"
        android:layout_marginTop="5dip"
        android:text="your changing text" />
</RelativeLayout> 
Run Code Online (Sandbox Code Playgroud)

in activity将此布局提供给微调器:

Spinner mySpinner = (Spinner) findViewById(R.id.yourSpinner);
        mySpinner.setAdapter(new MyAdapter(this, R.layout.custom_spinner,
                spinnerValues));
Run Code Online (Sandbox Code Playgroud)

  • 你应该使用 `sp` 而不是 `textSize` 的像素。 (2认同)
  • 您谈论创建一个名为“custom_spinner”的自定义微调器,但提供的布局甚至不包含名为“custom_spinner”的微调器,该示例没有帮助。 (2认同)