Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

Calin Bogdan
Calin Bogdan
14,921 Points

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

Calin Bogdan
Calin Bogdan
14,921 Points

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.

Calin Bogdan
Calin Bogdan
14,921 Points

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

Calin Bogdan
Calin Bogdan
14,921 Points

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'

Calin Bogdan
Calin Bogdan
14,921 Points

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'

Calin Bogdan
Calin Bogdan
14,921 Points

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").

Calin Bogdan
Calin Bogdan
14,921 Points

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: