【问题标题】:Spinner title should be an image and subtitle to be text微调标题应该是图像,副标题应该是文本
【发布时间】:2013-11-19 13:39:02
【问题描述】:
【问题讨论】:
标签:
android
android-actionbar
actionbarsherlock
android-actionbar-compat
【解决方案1】:
在 setOnItemSelected 监听器上,
你可以写
if (((TextView) view) != null) {
((TextView) view).setText(null);
}
这样您将只显示图标而不显示文本。并将背景设置为您想要的可绘制图标。
希望对您有所帮助。
【解决方案2】:
您需要选择一个按钮并将任何图像设置为其背景。然后单击按钮调用 Spinner.performClick() 以打开微调器。
以下是实现相同功能的代码。
在xml文件中:
<Button
android:id="@+id/font"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="50dp"
android:layout_weight="0.5"
android:background="@drawable/textsel" />
<Spinner
android:id="@+id/spin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_weight="0.5"
android:dropDownHorizontalOffset="0dp"
android:dropDownVerticalOffset="20dp"
android:dropDownWidth="500dp"
android:paddingTop="2sp"
android:spinnerMode="dropdown" >
</Spinner>
在 Java 类中:
Spinner spin = (Spinner) findViewById(R.id.spin);
Button typetext = (Button) findViewById(R.id.font);
typetext.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
spin.performClick();
}
});