gpt4 book ai didi

Android私有(private)样式使用

转载 作者:太空宇宙 更新时间:2023-11-03 12:35:56 26 4
gpt4 key购买 nike

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

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

因为谷歌将其设为私有(private)。但是我如何结合两种样式:ListSeparator 和边距?

样式一

<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="?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>

您可以从中修改边距。

关于Android私有(private)样式使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19399015/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com