Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Styles and Themes in Android Using Styles in Layouts Creating a Style

Styles and Themes in Android

Now add an item element to the styles that sets the text color of the Button to blue. Hint:Use android :text Color as the attribute name and #0000ff as the hex code for blue

styles.xml
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name ="TweetButton">
<item name="android:textColor"#0000ff>
</resources>
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <Button
        android:id="@+id/sendButton"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/send_button_label" />

</RelativeLayout>

1 Answer

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

Hi there,

The item element is a child of the style element in XML, so what you need to do is pass the blue value in directly as a value, but not as its own attribute. Like this.

<resources xmlns:android="http://schemas.android.com/apk/res/android">
  <style name ="TweetButton">
    <item name = "android:textColor">#0000ff</item>
  </style>
  </resources>

Item has a closing tag and isn't self closing. That's how the style knows how to recognise styles and settings :)