更改listSeparatorTextViewStyle用线的颜色 [英] Change the line color used in listSeparatorTextViewStyle

查看:976
本文介绍了更改listSeparatorTextViewStyle用线的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的code

        <TextView
            android:text="@string/hello"
            style="?android:attr/listSeparatorTextViewStyle" />

和我将得到以下效果。

不过,我不开心的颜色一致。我想有像

However, I am not happy with the color line. I would like to have something like

我想它有蓝色线在全息图像。我尝试以下自定义样式。

I would like it to have blue color line as in holo. I try the following custom style.

<style name="MyOwnListSeperatorTextViewStyle">        
<item name="android:background">@android:drawable/list_section_divider_holo_light</item>        
<item name="android:textAllCaps">true</item>    

<!-- Copy from Widget.TextView.ListSeparator -->

<item name="android:background">@android:drawable/dark_header_dither</item>
    <item name="android:layout_width">match_parent</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:textStyle">bold</item>
    <item name="android:textColor">?textColorSecondary</item>
    <item name="android:textSize">14sp</item>
    <item name="android:gravity">center_vertical</item>
    <item name="android:paddingLeft">8dip</item>        
</style>

但它不会工作,因为我碰到下面的错误。

But it won't work, as I get the following error.

错误:错误:资源是不公开的。 (在'机器人:背景,值为@android:绘制/ dark_header_dither')

有想法我怎么可以更改 listSeparatorTextViewStyle

Have idea how can I change the line color used in listSeparatorTextViewStyle?

推荐答案

我需要做这个覆盖典型的全息微调的风格(我不想带下划线的项目 - 我只是想箭头),我认为这可在$ P $重写pcisely相同的方式:

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:

首先,你要找到你想在Android风格的源覆盖的项目。所以有一个非常有用的回答包含了所有的样式(和名称来替代它们)就在这里:<一href="http://stackoverflow.com/questions/10679819/set-dialog-theme-to-parent-theme-in-android/11397502#11397502">Set对话的主题为Android中父主题

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

我相信你是以下行:

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

这需要我们的旅程寻找风格Widget.Holo.Light.TextView.ListSeparator应该有地方住你自己的电脑上!但我会做很容易,只是C和,P是:

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>

现在,你可能要适可而止,和只是看那个背景绘制。你会发现它是一个看起来像你试图避免险恶的灰线灰9patch文件。

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.

我们需要重写此。我相信,有许多方法可以做到这一点,但我这样做,通过自定义应用程序的主题。下面是的themes.xml文件:

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>

注意,我们使用了 listSeparatorTextViewStyle 从previous SO张贴?而自定义样式的父母是 Widget.TextView.ListSeparator 从Android的风格源?一切都非常重要。

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.

现在你只需要将此主题应用到您的应用程序,但我假设你有一个主题了。如果你还没有,你需要的使自己的9patch 的,但我只是想看看你的计算机上的list_section_divider_holo_light.9.png文件,并进行了灰蓝色的部分,然后进行复制,并把它变成自己的可绘制文件夹。

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!

这篇关于更改listSeparatorTextViewStyle用线的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆