如何在Android:ATTR的工作作风? [英] How does an android:attr style work?

查看:160
本文介绍了如何在Android:ATTR的工作作风?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过布局来构建一个Android UI。我开始用下面的:

I'm trying to build an Android UI via layouts. I start with the following:

<TextView
    android:id="@+id/..."
    android:layout_marginTop="8dip"
    android:text="..."
    style="?android:attr/listSeparatorTextViewStyle"/>

这看起来很不错(全部大写,字体较小,分栏下方的话)。现在我想延长的风格,所以我将其更改为以下内容:

And that looks good (all caps, smaller font, dividing bar underneath it). Now I want to extend the style, so I change it to the following:

<TextView
    android:id="@+id/..."
    android:layout_marginTop="8dip"
    android:text="..."
    style="@style/section_title"/>

通过的风格:

<style name="section_title" parent="@android:attr/listSeparatorTextViewStyle">
    <item name="android:layout_width">fill_parent</item>
    <item name="android:layout_height">wrap_content</item>
</style>

和不工作(字体是正确的,但分隔线消失)。

And that doesn't work (font is correct, but the divider line is gone).

怎么会......是什么?

How come... that?

推荐答案

当你使用:

style="?android:attr/listSeparatorTextViewStyle"

您正在使用该属性指向( listSeparatorTextViewStyle )的样式。如果你在这个平台的themes.xml 你会看到,实际上是用于该属性的风格是 Widget.TextView.ListSeparator.White 。因此,这是风格你应该继承您的自定义样式。

you're using the style pointed by this attribute(listSeparatorTextViewStyle). If you look in the platform themes.xml you'll see that the style that is actually used for this attribute is Widget.TextView.ListSeparator.White. So this is the style you should extend in your custom style.

不幸的是这种风格是私人的,不能扩展,或者你不应该扩展它(仅供参考,看的从谷歌这个错误报告)。你最好的办法是复制整个风格, Widget.TextView.ListSeparator.White Widget.TextView.ListSeparator 而不是风格从Android平台的延伸是不公开的,以及因此不得不也复制),您的自定义样式和使用的(见的从上面的链接此响应)。

Unfortunately that style is private and you can't extend it, or you shouldn't extend it(for reference, see this bug report from google). Your best option would be to copy that entire style, Widget.TextView.ListSeparator.White(Widget.TextView.ListSeparator isn't public as well so would have to also copy that), in your custom style and use that instead of extending the style from the android platform(see this response from the link above).

这篇关于如何在Android:ATTR的工作作风?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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