Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7398949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T03:56:24+00:00 2026-05-29T03:56:24+00:00

I’ve begun playing around with styles and such in my android applications, and I

  • 0

I’ve begun playing around with styles and such in my android applications, and I have gotten everything working so far. I quite understood the ‘style’ section of the guide.

But, looking around, as in this thread, I can’t really figure out the difference between the two (declare-stylable and style).
From my understanding declare-styleable takes the attribute specified in it and specifies it as styleable, and then from the code one changes it as he wants.

But if this is what it really does, wouldn’t it be simpler to just define the attribute in the layout? Or declare a style specifying it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T03:56:26+00:00Added an answer on May 29, 2026 at 3:56 am

    I think there is only the following difference between declaring an attribute as styleable or not.

    In attrs.xml you can declare custom attributes, either directly within the “resources” section or within “declare-styleable”:

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
       <attr name="attrib1" format="string" />
     <declare-styleable name="blahblah">
        <attr name="attrib2" format="string" />
     </declare-styleable>
    

    So now we defined “attrib1” as non-styleable and “attrib2” as styleable.

    In layout/someactivity.xml we can use these attributes directly (no namespace needed):

    <com.custom.ViewClass  attrib1="xyz" attrib2="abc"/>
    

    You can use the “styleable” attribute “attrib2” within a style.xml declaration. Again, no namespace is needed here (even if a namespace was used in the layout XML).

     <style name="customstyle" parent="@android:style/Widget.TextView">
        <item name="attrib2">text value</item>
        <!--  customize other, standard attributes too: -->
        <item name="android:textColor">@color/white</item>
     </style>
    

    Then you can also set the attributes per style.

    <com.custom.CustomView attrib1="xyz" style="@style/customstyle"/>
    

    Let us assume that we do this: we set attrib1 directly in XML, and we set attrib2 in a style.

    Elsewhere I have seen descriptions stating that “blahblah” must be the name of the custom view class that uses these attributes, and that you need to use a namespace to refer to your custom attributes in the layout XML. But none of this seems to be necessary.

    The difference between styleable and non-styleable seems to be that:

    • You can use styleable attributes in “style.xml” declarations.
    • The constructor of the custom class needs to read the styled and the non-styled attributes in a different way: the styled attributes with obtainStyledAttributes(), and the non-styled attributes with attr.getAttributeValue() or similar.

    In most tutorials and examples I’ve seen on the Web, only the obtainStyledAttributes() was used. However, this does not work with attributes declared directly in layout, without using a style. If you do obtainStyledAttributes() as shown in most tutorials, you will not get the attribute attrib1 at all; you will only get attrib2 since it was declared in the style. The direct method using attr.getAttributeValue() works:

     public CustomView(Context context, AttributeSet attrs) {
        super(context, attrs);
        String attrib1 = attrs.getAttributeValue(null, "attrib1");
        // do something with this value
     }
    

    Since we used no namespace to declare “attrib1“, we pass null as the namespace argument in getAttributeValue().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.