Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/212.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在样式声明中指定时未应用ListView分隔符_Android - Fatal编程技术网

Android 在样式声明中指定时未应用ListView分隔符

Android 在样式声明中指定时未应用ListView分隔符,android,Android,这更像是“为什么?”而不是“如何”的问题,因为我知道解决这个问题的简单方法。但我想知道我要描述的行为背后的逻辑是什么 我有一个样式声明和一些列表视图。我想改变一下分隔器的外观。我使用了以下声明: <style name="Theme.MyApp.Dark" parent="@style/Theme.Sherlock"> <item name="android:dividerHeight">4px</item> <item name="an

这更像是“为什么?”而不是“如何”的问题,因为我知道解决这个问题的简单方法。但我想知道我要描述的行为背后的逻辑是什么

我有一个样式声明和一些列表视图。我想改变一下分隔器的外观。我使用了以下声明:

<style name="Theme.MyApp.Dark" parent="@style/Theme.Sherlock">
    <item name="android:dividerHeight">4px</item>
    <item name="android:divider">#123456</item>
</style>
<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"/> 

您必须像这样在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"/> 


否则这将不起作用。

可以从主题设置,但需要一些技巧:

<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>

@样式/MyListViewStyle
#F00
1px

Rgrds;)

样式在清单文件中全局指定。如果它根本不被应用,dividerHeight也不会起作用。你也尝试过引用样式中的父属性吗???like parent=“@style/Theme.Dark”
   <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"/> 
<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>