Change the line color used in listSeparatorTextViewStyle

前端 未结 1 1292
南笙
南笙 2020-12-08 06:03

I have the following code

        

        
相关标签:
1条回答
  • 2020-12-08 06:32

    I needed to do this to override the typical Holo Spinner style (I didn't want the underlined item - i just wanted the arrow), and I think this can be overridden in precisely the same manner:

    First off, you want to find the item you wish to override in the android styles source. There is an incredibly useful SO answer that contains all of the styles (and the names to override them) right here: Set Dialog theme to parent Theme in Android

    I believe yours is the following line:

    <item name="listSeparatorTextViewStyle">@android:style/Widget.Holo.Light.TextView.ListSeparator</item>
    

    This takes us on a journey to find the style Widget.Holo.Light.TextView.ListSeparator which should live somewhere on your very own computer! But I'll make it easy and just c&p it:

    <style name="Widget.Holo.Light.TextView.ListSeparator" parent="Widget.TextView.ListSeparator">
        <item name="android:background">@android:drawable/list_section_divider_holo_light</item>
    </style>
    

    Now, you probably want to leave well enough alone, and just look at that background drawable. You will find it is a grey 9patch file that looks like the sinister grey line you seek to avoid.

    We need to override this. I am sure there are a number of ways to do this, but I do so by customizing the theme of the application. Here is the themes.xml file:

    <style name="AppTheme" parent="@android:style/Theme.Holo.Light.NoActionBar">
        <item name="android:listSeparatorTextViewStyle">@style/MyOwnListSeperatorTextViewStyle</item>
    </style>
    
    <style name="MyOwnListSeperatorTextViewStyle" parent="Widget.TextView.ListSeparator">
        <item name="android:background">@drawable/make_your_own_blue_9_patch_here</item>
    </style>
    

    Notice how we used the listSeparatorTextViewStyle from that previous SO post? And the parent of the custom style is the Widget.TextView.ListSeparator from android's style source? All very important.

    Now you just need to apply this theme to your app, but I am assuming you have a theme already. If you haven't already, you will need to make your own 9patch but I would just look at the list_section_divider_holo_light.9.png file on your computer, and make the grey parts blue, and then make a copy and place it into your own drawables folder.

    Hope this works and is helpful!

    0 讨论(0)
提交回复
热议问题