gpt4 book ai didi

android - styles.xml 中的自定义属性

转载 作者:IT老高 更新时间:2023-10-28 12:54:40 26 4
gpt4 key购买 nike

我创建了一个自定义小部件,并在 layout.xml 中声明它。我还在 attr.xml 中添加了一些自定义属性。但是,当尝试在styles.xml 中以样式声明这些属性时,它给了我No resource found that matches the given name: attr 'custom:attribute'.

我已经把 xmlns:custom="http://schemas.android.com/apk/res/com.my.package"在styles.xml 中的所有标签中,包括<?xml> , <resources> , 和 <style> ,但它仍然给我同样的错误,它找不到我的自定义 XML 命名空间。

但是,我可以使用我的命名空间手动为 layout.xml 中的 View 分配属性,因此命名空间没有任何问题。我的问题在于让 styles.xml 知道我的 attr.xml。

最佳答案

我想通了!答案是NOT在样式中指定命名空间。

<?xml version="1.0" encoding="utf-8" ?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="CustomStyle">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>

<item name="custom_attr">value</item> <!-- tee hee -->
</style>
</resources>

关于android - styles.xml 中的自定义属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6860886/

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