style attribute isn't applied

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

style attribute isn't applied

Postby GermanDev » Sat Jul 04, 2009 10:10 pm

Hi!

I have a list of buttons that I whant to style identically.

So I created a new style in values/styles.xml:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <style name="ButtonStyle">
  2.  
  3.         <item name="android:layout_width">fill_parent</item>
  4.  
  5.         <item name="android:layout_height">wrap_content</item>
  6.  
  7.         <item name="android:layout_marginTop">14sp</item>
  8.  
  9.         <item name="android:layout_marginBottom">?android:layout_marginTop</item>
  10.  
  11. </style>
Parsed in 0.002 seconds, using GeSHi 1.0.8.4


and applied it to the buttons:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2. <Button style="@style/ButtonStyle" android:id="@+id/button1" android:text="@string/button1"></Button>
  3.  
  4.  
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


But the button is invisble on the layout. If I add the attributes defined in the layout to each button, the button is shown correctly.

Where is my mistake?

Thank you in advance!
GermanDev
Freshman
Freshman
 
Posts: 7
Joined: Sun May 24, 2009 12:58 pm

Top

Re: style attribute isn't applied

Postby pskink » Sun Jul 05, 2009 10:12 am

GermanDev wrote:Hi!

I have a list of buttons that I whant to style identically.

So I created a new style in values/styles.xml:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <style name="ButtonStyle">
  2.         <item name="android:layout_width">fill_parent</item>
  3.         <item name="android:layout_height">wrap_content</item>
  4.         <item name="android:layout_marginTop">14sp</item>
  5.         <item name="android:layout_marginBottom">?android:layout_marginTop</item>
  6. </style>
Parsed in 0.006 seconds, using GeSHi 1.0.8.4



you have to specify parent in your style definition, see system styles.xml for more info
pskink
pskink
Master Developer
Master Developer
 
Posts: 719
Joined: Mon Nov 24, 2008 3:49 pm

Postby GermanDev » Sun Jul 05, 2009 3:04 pm

where can I find the system styles.xml?
GermanDev
Freshman
Freshman
 
Posts: 7
Joined: Sun May 24, 2009 12:58 pm

Postby zoniq » Thu Oct 29, 2009 12:09 pm

GermanDev wrote:where can I find the system styles.xml?

  • anything in android.R.styleable can be used inside a style body as a subject for styling (using the item tag)
  • anything in android.R.style can be used as parent styles to inherit from
Source: http://brainflush.wordpress.com/2009/03 ... nd-styles/
zoniq
Junior Developer
Junior Developer
 
Posts: 21
Joined: Mon Sep 28, 2009 12:33 pm

Postby zoniq » Thu Oct 29, 2009 12:12 pm

Btw, using this:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2.  
  3. <resources>
  4.  
  5.         <style name="HomeItemDescText" parent="@android:style/TextAppearance">
  6.  
  7.                 <item name="android:textStyle">bold</item>
  8.  
  9.                 <item name="android:textColor">#000000</item>
  10.  
  11.                 <item name="android:textSize">8dip</item>
  12.  
  13.         </style>
  14.  
  15.  
  16.  
  17.         <style name="HomeItemNumText">
  18.  
  19.                 <item name="android:textColor">#FFFFFF</item>
  20.  
  21.         </style>
  22.  
  23. </resources>
Parsed in 0.002 seconds, using GeSHi 1.0.8.4

works perfectly without using the parent attribute. It doesn't show up correctly in Eclipse's XML design view, but it works perfect when running the code. Didn't test with other elements, though.
zoniq
Junior Developer
Junior Developer
 
Posts: 21
Joined: Mon Sep 28, 2009 12:33 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: Google Feedfetcher and 8 guests