2014-08-29 30 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> 
... 
相關問題