【问题标题】:Spinner not showing the selected text only on Motorola Defy 2.2?Spinner 仅在 Motorola Defy 2.2 上不显示所选文本?
【发布时间】:2013-06-20 00:38:45
【问题描述】:

我有一个奇怪的问题,关于在我的摩托罗拉 Defy 2.2 中显示从微调器中选择的文本。我创建了一个布局,它有一个微调器,用户可以从中选择一个选项,但问题是即使我从微调器列表中选择了一个项目它永远不会在框中显示该项目。我知道默认情况下 defy 中的文本颜色是白色,我的布局背景也是白色的,这会隐藏文本,但我还在布局中为微调器指定了 text-color 属性为黑色它仍然不显示文本。我的布局如下所示:

<?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="match_parent"
    android:orientation="vertical" >
    <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="20.0dip"
                android:layout_marginRight="20.0dip"
                android:layout_marginTop="7.0dip"
                android:background="@drawable/rectangle_shape" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:layout_gravity="right|center"
                    android:gravity="right|center"
                    android:paddingBottom="7.0dip"
                    android:paddingLeft="10.0dip"
                    android:paddingRight="8.0dip"
                    android:paddingTop="7.0dip"
                    android:text="Concession"
                    android:textColor="@color/white"
                    android:textSize="16.0sp" />

                <Spinner
                    android:id="@+id/CSpinner"
                    android:layout_width="0.0dip"
                    android:layout_height="fill_parent"
                    android:layout_weight="1.0"
                    android:background="@drawable/rectangle_shape_middle"
                    android:entries="@array/C_arrays"
                    android:paddingLeft="6.0dip"
                    android:prompt="@string/C_prompt"
                    android:textColor="@color/black"
                    android:textSize="16.0sp" />

                <ImageView
                    android:id="@+id/SpinnerSelector"
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:layout_gravity="right"
                    android:background="@drawable/rectangle_shape_end"
                    android:paddingLeft="3.0dip"
                    android:paddingRight="3.0dip"
                    android:src="@drawable/ic_navigation_expand" />
            </LinearLayout>
</LinearLayout>

该代码在三星 Galaxy s2、s3 和 Note 等其他手机上也能正常工作。请帮帮我。

提前致谢

【问题讨论】:

  • 我认为 Spinner 没有属性 android:textColor。也许我需要为此使用 java。
  • 我找到了我的解决方案here

标签: android android-layout android-spinner


【解决方案1】:

我正在回答我自己的问题,因为它可能对其他人有所帮助。摩托罗拉 defy 的问题是它的默认文本颜色设置为白色,对于微调器,我们不能使用 android:textColor="@color/white",因为它们不起作用。更改微调器的文本颜色,我们需要使用以下代码:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="MooTheme" parent="android:Theme">
        <item name="android:spinnerItemStyle">@style/MooSpinnerItem</item>
    </style>

    <style name="MooSpinnerItem" parent="android:Widget.TextView.SpinnerItem">
        <item name="android:textAppearance">@style/MooTextAppearanceSpinnerItem</item>
    </style>

    <style name="MooTextAppearanceSpinnerItem" parent="android:TextAppearance.Widget.TextView.SpinnerItem">
        <item name="android:textColor">#F00</item>
    </style>
</resources>

现在我们只需要将 MooTheme 应用到我们的应用程序,您就会开始在 spinner 中看到文本。

【讨论】:

  • 谢谢&lt;item name="android:spinnerItemStyle"&gt;@style/MooMooTheme&lt;/item&gt; 这对我有用..
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-09-24
  • 2020-10-17
  • 1970-01-01
  • 2015-04-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多