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>

从那里你可以修改边距.

上一篇:PLSQL_性能优化系列06_Oracle Soft Parse / Hard Parse软硬解析


下一篇:react笔记积累