2011-12-26 45 views
4

這更「爲什麼?」比「如何?」問題,因爲我知道問題的一個簡單的解決方法。但我想知道我要描述的行爲背後的邏輯。在樣式聲明中指定時,不應用ListView分隔符

我有一個樣式聲明和一些ListViews。我想改變分隔線的樣子。我使用以下聲明:

<style name="Theme.MyApp.Dark" parent="@style/Theme.Sherlock"> 
    <item name="android:dividerHeight">4px</item> 
    <item name="android:divider">#123456</item> 
</style> 

我的娛樂,只有分頻器的高度被應用。我試過用alpha值(#12345678)和漸變繪製指定顏色,沒有任何作用。 ListViews是這樣聲明的:

<ListView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/list" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"/> 

所以,你可以看到沒有任何東西可以重寫樣式聲明。我只能改變除法時,我直接在ListView控件聲明中指定它:

<ListView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/list" 
    android:divider="#123456" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"/> 

用我的新收購的specifying colors depending on theme selected技能,我可以解決這很容易 - 我只是有自定義顏色屬性來聲明android:divider爲每個列表。

但是爲什麼我不能改變android:divider的風格,就像android:dividerHeight?這有什麼理由嗎?我找不到解釋,錯誤報告或類似的東西讓我理解這種行爲。

編輯:主題是全局應用,該清單文件:

<application android:icon="@drawable/icon" android:label="@string/app_name" android:name="org.my.app" android:theme="@style/Theme.MyApp.Dark"> 

回答

1

就不得不提到的樣式在Lisview這樣

<ListView xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/list" 
     style = "@style/Theme.MyApp.Dark" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"/> 

否則這不會工作..

+0

樣式在Manifest文件中全局指定。如果它根本不適用,dividerHeight不會工作。 – user1234567

+0

你是否在清單中將此稱爲主題.... ?? –

+0

是的,我更新了這個問題來說明問題。 – user1234567

5

它可以設置從一個主題,但有一個小技巧:

<style name="MyTheme" parent="AppTheme"> 
     <item name="android:listViewStyle">@style/MyListViewStyle</item> 
</style> 

<style name="MyListViewStyle" parent="@android:style/Widget.ListView"> 
     <item name="android:divider">#F00</item> 
     <item name="android:dividerHeight">1px</item> 
</style> 

Rgrds;)