android - Using A Custom Attribute That Is In A Style With A View -
android - Using A Custom Attribute That Is In A Style With A View -
lets have custom attribute in few styles so:
<style name="theme1" parent="android:theme.holo"> <item name="textviewbackground">#000022</item> <item name="android:background">#000000</item> </style> <style name="theme2" parent="android:theme.holo"> <item name="textviewbackground">#aa2200</item> <item name="android:background">#000000</item> </style>
can reference in standard view textview? like:
<textview android:id="@+id/txtnumber" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@currenttheme.textviewbackground" android:text="number" />
you need define textview style, this:
<style name="theme1" parent="android:theme.holo"> <item name="android:textviewstyle">@style/textviewstyle1</item> <item name="android:background">#000000</item> </style> <style name="theme2" parent="android:theme.holo"> <item name="android:textviewstyle">@style/textviewstyle2</item> <item name="android:background">#000000</item> </style> <style name="textviewstyle1" parent="@android:style/widget.textview"> <item name="android:background">#000022</item> </style> <style name="textviewstyle2" parent="@android:style/widget.textview"> <item name="android:background">#aa2200</item> </style>
then won't need set android:background
attribute on each textview
in xml, apply textview
s not specify different background.
android android-layout
Comments
Post a Comment