开发者

Style / themes not working

whenever I try to apply a VERY simple style in eclipse I get errors: the style is as below (filename styles.xml in res/layout)

<?xml version="1.0" encoding="utf-8"?>
<resou开发者_开发技巧rces>
    <style name="commonStyle">
       <item name="android:background">#EEEEEE</item>
     </style>
</resources>

Regardless of whether I try to apply this to a LinearLayout (using style="@style/commonStyle") or to an activity in my manifest file (using android:theme="@style/commonStyle") I ALWAYS get the error "No resource found that matches the given name...". If I try to apply an Android theme to an activity (say Theme.Black) it works just fine. If I remove any usage of my style, my R.java file is generated as normal with the following contents:

    public static final int styles=0x7f030002; (in the generated layout class)

I have NO idea what is going on. It seems that NOONE is having the same troubles as me (Ive spent about 4 hours searching using google, and came up with not even a remotely close answer).

Ive tried restarting eclipse, clean building etc. etc. and nothing works what so ever... So what am I missing?


Try moving your styles.xml file to res/values.

http://developer.android.com/guide/topics/resources/style-resource.html


Styles need to be stored in the res/values folder :)

http://developer.android.com/guide/topics/ui/themes.html (See Defining Styles)

The name of the XML file is arbitrary, but it must use the .xml extension and be saved in the res/values/ folder.


I haven't used styles in my code yet, however generally you need to use android: Does it work when you use this?:

<style android:name="commonStyle">


Please verify the you call the style in the correct manner :

for example this might compile but will not work :

style="mainButtonText"

this is the correct way to call style:

style="@style/mainButtonText"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜