【问题标题】:Spinner with custom background not showing text具有自定义背景的微调器不显示文本
【发布时间】:2012-05-21 10:56:29
【问题描述】:

我有一对完全按预期工作的 Spinner,但是当我在它们上放置一个可绘制对象时,文本就消失了。这是 Layout 和 Drawable 的 XML。这里唯一的问题是drawable不让文本显示出来。

ttd_list.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >

<include
    android:id="@+id/include1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    layout="@layout/action_bar" />

<LinearLayout
    android:id="@+id/ll1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" android:background="@color/gray">

    <RelativeLayout
        android:id="@+id/relativeLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:descendantFocusability="beforeDescendants"
        android:focusableInTouchMode="true"
        android:paddingBottom="8dip" >

        <AutoCompleteTextView
            android:id="@+id/autoCompleteThingsToDo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_marginTop="8dip"
            android:layout_toLeftOf="@+id/buttonSearchThingsToDo"
            android:textColor="#000000" >
        </AutoCompleteTextView>

        <Button
            android:id="@+id/buttonSearchThingsToDo"
            style="@style/StandardButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignTop="@+id/autoCompleteThingsToDo"
            android:text="@string/search" />
    </RelativeLayout>

    <TableRow
        android:id="@+id/tableRow1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingBottom="8dip" >

        <Spinner
            android:id="@+id/spinnerCategories"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@drawable/spinner_filters" />

        <View
            android:layout_width="10dip"
            android:layout_height="match_parent" />

        <Spinner
            android:id="@+id/spinnerSortOrder"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@drawable/spinner_filters" />
    </TableRow>
</LinearLayout>

<ListView
    android:id="@+id/listViewThingsToDo"
    android:layout_width="match_parent"
    android:layout_height="0dip"
    android:layout_weight="1" >
</ListView>

spinner_filters.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item android:drawable="@drawable/spinnerbg" android:state_pressed="true"><shape>
        <solid android:color="@color/blue" />

        <stroke android:color="@color/blue" />

        <corners android:radius="3dp" />
    </shape></item>
<item android:drawable="@drawable/spinnerbg" ><shape>
        <solid android:color="#00000000" />

        <corners android:radius="3dp" />
    </shape></item>

</selector>

spinnerbg.9.png:

知道为什么文本不显示吗?

编辑:好的,已经解决了。问题出在 9.png 文件上,设计不正确。

【问题讨论】:

  • 您能详细说明问题所在吗?我也面临同样的问题。
  • @Niels 这是一个简单的问题:您只需要使用 sdk 工具编辑您的 9.png。您必须将包含文本的像素向下和向右放置。

标签: android drawable nine-patch android-spinner


【解决方案1】:

里面的文字可能是白色的。尝试更改背景的颜色,以确保...

【讨论】:

  • 我已经尝试过改变颜色。实际上,蓝色三角形和底线之外的背景是透明的。我将包含微调器的布局颜色更改为黑色和白色,但我看不到文本。
猜你喜欢
  • 2012-09-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-02-07
  • 1970-01-01
相关资源
最近更新 更多