微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Android私密样式使用

尝试继承Widget.TextView.ListSeparator样式,但现在aapt不允许这样做:

No resource found that matches the given name
‘Widget.TextView.ListSeparator

因为谷歌把它变成了私有的.但是我如何组合两种样式:ListSeparator和margin?

风格1

<style name="settings_plain_text">
<item name="android:layout_marginTop"> 10sp </item>
<item name="android:layout_marginBottom"> 10sp </item>
<item name="android:textSize"> 18sp </item>

风格2

style="?android:attr/listSeparatorTextViewStyle"

解决方法:

我复制了这个link的答案:

Hello all. I did some investigating with the frameworks team who’s in charge of aapt.
What is happening is that some styles, like WindowTitle are not public (you won’t find them in android.R.style). You should not be extending non public resources. aapt used to let you do that but it was a bug which was fixed in platform-tools r6.

The issue is that once compiled, resources are assigned an integer. In this case your custom style is assigned an integer and its parent is referenced through the parent integer.

For the framework, only public resources are guaranteed to only have the same integer, build after build. The integer of private resources integer will change from build to build.

This means that your custom style is referencing a parent that will not be valid once installed on a device. It’ll referenced either another resources or none at all, and it won’t do what you want.

If you wish to reuse a style that is private, you should copy the content of that style into your own instead of extending it.

我发现谷歌搜索的风格是that one

<style name="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:paddingStart">8dip</item>
</style>

从那里你可以修改边距.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。