Ansh
Ansh

Reputation: 2396

Spinner not showing the selected text only on Motorola Defy 2.2?

I have a strange issue regarding showing text selected from spinner in my motorola Defy 2.2 .I have created a layout which has a spinner from which user can select one option, but the problem is even though I select an item from spinner list it never display that item in box.I know the text-color in defy by default is white and my layout background is also white which would hide the text, but I have also specified the text-color property in layout for spinner as black color and it still not displaying the text.My layout looks like the following:

<?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>

The code is working fine on other phones like samsung galaxy s2,s3 and Note as well.Please help me out.

Thanks in Advance

Upvotes: 0

Views: 1240

Answers (1)

Ansh
Ansh

Reputation: 2396

I am answering my own question as it might help others.The problem with Motorola defy is that it has a default text color set to white and for spinner we can't use android:textColor="@color/white" as they won't work.To change text color of spinner we need use following code:

<?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>

Now we just need to apply MooTheme to our application and you will start seeing the text in spinner.

Upvotes: 1

Related Questions