【问题标题】:Changing background color of spinner hides dropdown arrow更改微调器的背景颜色隐藏下拉箭头
【发布时间】:2015-07-07 13:37:54
【问题描述】:

我有一个微调器并将其背景颜色设置为白色。问题是,箭不见了。我不知道为什么。有什么问题吗?

我正在使用此代码。

drivers = (Spinner) findViewById(R.id.spinner1);
drivers.setBackgroundColor(Color.WHITE);

ArrayAdapter<String> adp1=new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item , driverList);
adp1.setDropDownViewResource(android.R.layout.select_dialog_singlechoice);
drivers.setAdapter(adp1);
drivers.setPrompt("Select Driver");

这是我的布局:

<Spinner
    android:id="@+id/spinner1"
    android:layout_width="330dp"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_marginTop="10dp"
    android:ellipsize="marquee"/>

有什么想法吗?我想保留白色背景,但应该显示下拉箭头。

【问题讨论】:

  • 尝试给 match_parent 赋予它的宽度
  • “pass”代表什么?
  • 我的错,贴错了行。
  • 箭头不显示在右侧?
  • 如果您设置 Spinner 自定义背景颜色,则它会填充所有区域,包括箭头区域,因此最好使用箭头制作自定义背景并将其设置为 Spinner 背景而不是背景颜色。

标签: android android-layout android-spinner


【解决方案1】:

我解决了这个问题,用RelativeLayOut 包裹spinner 并为RelativeLayOut 使用背景。然后箭头不会消失。

<RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#f00" >
            <Spinner
        android:id="@+id/spinner1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    </RelativeLayout>

【讨论】:

    【解决方案2】:

    设置背景图片(带箭头)而不是color

    代码

    drivers.setBackgroundResource(R.drawable.spinner_img);
    

    【讨论】:

      猜你喜欢
      • 2015-11-14
      • 1970-01-01
      • 2015-05-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多