简体   繁体   English

Android私密样式使用

[英]Android private styles using

Trying to inherit Widget.TextView.ListSeparator style, but now aapt doesn´t allow to do this: 尝试继承Widget.TextView.ListSeparator样式,但现在aapt不允许这样做:

No resource found that matches the given name 'Widget.TextView.ListSeparator 找不到与给定名称'Widget.TextView.ListSeparator匹配的资源

because google made it private. 因为谷歌把它变成了私有的。 But how can I combine two styles : ListSeparator and margins? 但是我如何组合两种样式:ListSeparator和margin?

Style 1 风格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>

Style 2 风格2

style="?android:attr/listSeparatorTextViewStyle"

I copy the answer from this link : 我从这个链接复制答案:

Hello all. 大家好。 I did some investigating with the frameworks team who's in charge of aapt. 我做了一些调查负责aapt的框架团队。 What is happening is that some styles, like WindowTitle are not public (you won't find them in android.R.style). 发生的事情是一些样式,如WindowTitle不公开(你不会在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. aapt曾经让你这样做,但这是一个在平台工具r6中修复的bug。

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. 如果您希望重用私有样式,则应将该样式的内容复制到您自己的样式中,而不是将其扩展。

The style I have found googling is 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>

From that you can modify margins. 从那里你可以修改边距。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM