在样式声明中指定时,不应用ListView分隔符

use*_*567 4 android

这更"为什么?" 比"怎么样?" 问题,因为我知道这个问题的一个简单的解决方法.但是我想知道我要描述的行为背后的逻辑是什么.

我有一个样式声明和一些ListViews.我想改变分频器的外观.我使用以下声明:

<style name="Theme.MyApp.Dark" parent="@style/Theme.Sherlock">
    <item name="android:dividerHeight">4px</item>
    <item name="android:divider">#123456</item>
</style>
Run Code Online (Sandbox Code Playgroud)

令我愉快的是,只应用了分隔器的高度.我已经尝试用alpha值(#12345678)和渐变drawable指定颜色,没有任何效果.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"/> 
Run Code Online (Sandbox Code Playgroud)

所以,正如你所看到的,没有任何东西可以覆盖样式声明.我只能在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"/> 
Run Code Online (Sandbox Code Playgroud)

使用我新获得的根据所选主题指定颜色的技巧,我可以很容易地解决这个问题 - 我只需要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">
Run Code Online (Sandbox Code Playgroud)

Mar*_*ark 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>
Run Code Online (Sandbox Code Playgroud)

Rgrds;)