Android Spinner 下拉箭头不显示

标签 android xml layout fragment spinner

我的 fragment 背景是白色的,除非我点击它,否则微调器的箭头不会显示。

这是我的 Java 文件中的 fragment :

    spinner = (Spinner)v.findViewById(R.id.spinner);
    ArrayAdapter adapter = ArrayAdapter.createFromResource(getActivity(), R.array.accounts,R.layout.spinner_item);
    adapter.setDropDownViewResource(R.layout.spinner_dropdown_items);
    spinner.setAdapter(adapter);
    spinner.setPrompt("Select an account");

这是我用于 spinner_item 的 XML

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
style="?android:attr/spinnerItemStyle"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:textAlignment="inherit"
android:textSize="16dp"
android:background="#FFFFFFFF"
android:textColor="#ff252525"/>

这是我的 spinner_dropdown_items 的布局。

<?xml version="1.0" encoding="utf-8"?>

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
style="?android:attr/spinnerItemStyle"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:textAlignment="inherit"
android:textSize="16dp"
android:background="#FFFFFFFF"
android:textColor="#ff252525"/>

这是我的微调器在 fragment 的白色背景下的外观: White Colour Background - Spinner 这就是我将背景颜色更改为紫色时的样子: Purple background - Spinner

最佳答案

这对我有用,也更简单:

<Spinner
      android:id="@+id/spinner"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:theme="@style/ThemeOverlay.AppCompat.Light"
      android:spinnerMode="dropdown" />

在你的类文件中:

spinner = (Spinner) view.findViewById(R.id.spinner);
ArrayAdapter adapter = ArrayAdapter.createFromResource(this, R.array.spinner_data, android.R.layout.simple_spinner_dropdown_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);

希望这会有所帮助;)

关于Android Spinner 下拉箭头不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29009445/

相关文章:

flutter - 如何从flutter中计算widget的剩余大小?

Android - fill_parent 在relativelayout 中的行为不符合预期

php - 进行自定义用户布局的最佳方式

php - 如何让PHP和IOS Iphone加密通话?

android - 从 fragment 动态获取 ImageView 中的图像总是返回 0 作为 resourceid

xml - 如何通过 XPATH 检查元素是否存在于所有父元素中

c# - 拉出一些div标签并用c#放入json或xml文件格式

c# - 将 XSLT 中的模板附加到另一个 XSLT

android - 为什么人们喜欢在 android 中配对 CLEAR_TOP 和 SINGLE_TOP

在 Windows 7 x64 上使用 NDK r9b 的 android-cmake