android - 带有图像和文本的微调器

标签 android android-spinner

我希望我的微调器看起来像这样 enter image description here

只有最上面的标题应该有图像和文本。剩余的下拉菜单应该只有文本。 谁能帮我做这个。

我试过了..

我的xml文件

 <Spinner android:id="@+id/spinner1"
 android:layout_width="200dp"
 android:layout_height="50dp"
 android:layout_alignParentLeft="true"
 android:layout_below="@id/view" 
android:layout_marginLeft="35dp"
 android:layout_marginTop="20dp"
 android:background="@drawable/grey_btn"
 android:popupBackground="@drawable/drop_down_background"
 android:spinnerMode="dropdown" />

然后

ArrayAdapter<String> adapter1 = new ArrayAdapter<String>(mContext, R.drawable.spinner_text,R.id.customtextview,arr1); adapter1.setDropDownViewResource(R.drawable.drop_down); s1.setAdapter(adapter1);

最佳答案

您应该在适配器中同时拥有 getView 和 getDropDownView。通过这种方式,您可以为所选项目和列表的其余部分指定不同的外观。

在获取 View 中:

textView = (TextView) convertView.findViewById(R.id.spinner_item_text);
imageView = (ImageView) convertView.findViewById(R.id.spinner_item_image);
textView.setVisibility(ImageView.VISIBLE);
imageView.setVisibility(ImageView.VISIBLE);

在 getDropDownView 中:

textView = (TextView) convertView.findViewById(R.id.spinner_item_text);
imageView = (ImageView) convertView.findViewById(R.id.spinner_item_image);
textView.setVisibility(ImageView.VISIBLE);
imageView.setVisibility(ImageView.INVISIBLE);

关于android - 带有图像和文本的微调器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16667129/

相关文章:

android - 如何禁用 Android 上的切换按钮?

Android 将字符串写入文件花费的时间太长

android - 如何观察数据库中的变化以更新 LiveData

Android Spinner——如何调整当前所选项目的大小?

java - 如何使用 JSON 填充子项微调器?

android - 使用 withId 匹配器时 Espresso NoMatchingViewException

android - 是否有任何 API 支持以编程方式在 Android 中进行电话 session ?

java - 使用微调器更改 TextSize

android - Spinner getSelectedItem() 抛出异常

android - 如何让 Spinner 的默认值作为上次保存的值?Android