How to I tell my own custom Spinner Layout to use my Theme?
Styl开发者_JAVA百科e:
<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">
<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>
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.
You want your TextViews in the RelativeLayout to use the same text style?
Add "style=@style/SpinnerText"
attribute to the TextView.
精彩评论