tags:

views:

398

answers:

2

How to I tell my own custom Spinner Layout to use my Theme?

Style:

<style name="SpinnerText" parent="@android:style/Widget.TextView.SpinnerItem">
    <item name="android:textAppearance">@style/AnswerTextElement</item>
<item name="android:gravity">center_vertical|center_horizontal</item>
</style>

Theme:

 <style name="ApplicationTheme" parent="android:style/Theme.NoTitleBar">
    <item name="android:buttonStyle">@style/Button</item>
    <item name="android:spinnerStyle">@style/Spinner</item>
    <item name="android:spinnerItemStyle">@style/SpinnerText</item>
</style>

This works for default Spinners, however does not work with my custom layout:

<RelativeLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"&gt;
<TextView android:layout_height="wrap_content" android:id="@+id/text1"
    android:text="label name" android:layout_width="fill_parent"
    android:layout_toLeftOf="@+id/check1"></TextView>
<CheckBox android:layout_width="wrap_content"
    android:layout_height="wrap_content" android:id="@+id/check1"
    android:layout_alignParentRight="true" android:clickable="false"
    android:focusable="false" android:focusableInTouchMode="false"
    style="@style/CheckBoxPlainBackground"></CheckBox>
</RelativeLayout>
A: 

You want your TextViews in the RelativeLayout to use the same text style? Add "style=@style/SpinnerText" attribute to the TextView.

molnarm
I realise that but that would mean that if I changed that theme I would have to manually update they layout - I don't want to have to do that. Incidentally I tried adding @android:style/Widget.TextView.SpinnerItem as the style thinking it would then use the overridden style but it didn't work
jax
Did you try creating a custom view based on Spinner? Then you could style it simply. (http://developer.android.com/guide/topics/ui/custom-components.html#modifying)
molnarm
A: 

SOLVED:

You need to add

?android:attr/spinnerItemStyle

to the style attribute of the layout. Now it will act like the actual Spinner Item and all changed to the Theme will apply.

By the way - I found this in the SDK under YOUR_SDK\platforms\android-1.6\data\res\layout\simple_spinner_item.xml

You will be able to find other styles for other controls in this directory.

jax