2014-08-29 32 views
0

我尝试为API 8开发应用程序,但没有任何styles.xml的经验。对于应用程序中的活动,我使用Theme.Light。在玩风格之后,我得到了上面的错误。我也检查了这个门户网站上的其他帖子,我尝试了很多建议,但我无法进一步探讨。 styles.xml如下,希望有人会提出建议。试验样式=>找不到与给定名称匹配的资源:attr

<resources> 

<!-- 
    Base application theme, dependent on API level. This theme is replaced 
    by AppBaseTheme from res/values-vXX/styles.xml on newer devices. 
--> 
<style name="AppBaseTheme" parent="Theme.AppCompat.Light"> 
    <!-- 
     Theme customizations available in newer API levels can go in 
     res/values-vXX/styles.xml, while customizations related to 
     backward-compatibility can go here. 
    --> 
</style> 

<!-- Application theme. --> 
<style name="AppTheme" parent="AppBaseTheme"> 
    <!-- All customizations that are NOT specific to a particular API-level can go here. --> 
</style> 

<style name="ContactLabelTextView"> 
    <item name="layout_width">wrap_content</item> 
    <item name="layout_height">wrap_content</item> 
    <item name="layout_gravity">left|center_vertical</item> 
    <item name="layout_marginLeft">15dp</item> 
    <item name="layout_marginRight">5dp</item> 
    <item name="layout_marginTop">5dp</item> 
    <item name="clickable">false</item> 
    <item name="longClickable">false</item> 
    <item name="textSize">14sp</item> 
    <item name="textAppearance">?android:attr/textAppearanceMedium</item> 
    <item name="android:textColor">@android:color/black</item> 
    <item name="layout_marginBottom">5dp</item> 
</style> 

<style name="ContactMultiplineText" > 
    <item name="layout_width">match_parent</item> 
    <item name="layout_height">wrap_content</item> 
    <item name="layout_marginLeft">15dp</item> 
</style> 

+0

请粘贴整个堆栈跟踪。 – alanv 2014-08-29 22:38:11

+1

请看看http://brainflush.wordpress.com/2009/03/15/understanding-android-themes-and-styles/也许它会帮助你理解造型 – 2014-08-29 23:25:03

回答

0

你需要有一个parent style,使您能够调用它的属性。

样本:如果你希望你的textView中等大小的文本

<style name="ContactLabelTextView" parent="@android:style/TextAppearance.Medium"> 

上面的代码时,你仍然可以改变它什么都大小你想为你TextView

1

阅读后recommended by Alexander Zhak我对样式有了更好的理解。因此,我对styles.xml进行了一些修改,并且工作正常。这些修改是:

... 
<style name="ContactLabelTextView" parent="@android:style/TextAppearance.Medium"> 
    <item name="android:textSize">14sp</item> 
    <item name="android:textColor">@android:color/black</item> 
    <item name="android:longClickable">false</item> 
    <item name="android:clickable">false</item> 
</style> 

<style name="ContactLabelTextView.Layout"> 
    <item name="android:layout_width">wrap_content</item> 
    <item name="android:layout_height">wrap_content</item> 
    <item name="android:layout_gravity">left|center_vertical</item> 
    <item name="android:layout_marginLeft">15dp</item> 
    <item name="android:layout_marginRight">5dp</item> 
    <item name="android:layout_marginTop">5dp</item> 
    <item name="android:layout_marginBottom">5dp</item> 
</style> 

<style name="ContactMultiplineText"> 
    <item name="android:layout_width">match_parent</item> 
    <item name="android:layout_height">wrap_content</item> 
    <item name="android:layout_marginLeft">15dp</item> 
</style> 
... 
相关问题