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

I am lost,can someone help

i need help guys

styles.xml
<resources xmlns:android="http://schemas.android.com/apk/res/android">

</resources>

<!--Base application theme. -->
<style name="AppTheme" parent="android:Theme.Material.NoActionBar">
  <!--Customize your theme here.-->
  <item name="android:colorAccent">@android:color/darker_gray</item>

</style>

</style name="TweetButton">
    <item name="android:layout_height">64dp</item>
    <item name="android:layout_width">64dp</item>
    <item name="android:background">?android:attr/selectableItemBackgroundBorderless</item>

</style>
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>

10 Answers

Cheers!

You have to reference the style you just created to the Button element, like so:

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

Good luck!

What about on the styles section

Styles section is just fine.

I have tried again but in still getting

Bummer! Don't forget to add the 'style' element inside the 'resources' element.

Oh, I've missed that, sorry.

The <style> tags have to be inside <resources>. They are currently outside of it. That should fix all your issues.

so how can I make style be inside resource

Move the <style> tags between <resources> and </resources>, like so:

<resources xmlns:android="http://schemas.android.com/apk/res/android">
    <!--Base application theme. -->
    <style name="AppTheme" parent="android:Theme.Material.NoActionBar">
        <!--Customize your theme here.-->
        <item name="android:colorAccent">@android:color/darker_gray</item>    
    </style>

    <style name="TweetButton">
        <item name="android:layout_height">64dp</item>
        <item name="android:layout_width">64dp</item>
        <item name="android:background">?android:attr/selectableItemBackgroundBorderless</item>    
    </style>
</resources>

I think the first 1 have been solved, im now getting this new problem

Bummer! Make sure you set the 'name' attribute to 'TweetButton'

Copy the code from my last answer again, I edited the mistake.

im now having network challenge. Calin Bogdan thanks. I will continue tomorrow.

Im now having this error:-

Bummer! Make sure you set the 'name' attribute to 'TweetButton'

Oops! That's probably because I was using ':' instead of '=' on the layout xml file.

Make sure to change the following in the activity_main.xml file, at the Button element.

style:"@style/TweetButton" -> style="@style/TweetButton"

It is giving the same error after correcting (style:"@style/TweetButton") to this (style="@style/TweetButton").

Are you sure you corrected it in styles.xml too?

</style name="TweetButton">
        <item name="android:layout_height">64dp</item>
        <item name="android:layout_width">64dp</item>
        <item name="android:background">?android:attr/selectableItemBackgroundBorderless</item>    
    </style>

--->

<style name="TweetButton">
        <item name="android:layout_height">64dp</item>
        <item name="android:layout_width">64dp</item>
        <item name="android:background">?android:attr/selectableItemBackgroundBorderless</item>    
    </style>

Yes i have corrected it in styles.xml. im still getting the below message

Bummer! Make sure you set the 'name' attribute to 'TweetButton'.

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there, Elvis Chitsungo! I'm following up to make sure you got your issue resolved. I hope you did! If not, can I please see your current code for the challenge? Thanks :sparkles: