gpt4 book ai didi

android - styles.xml 中使用的自定义 attrs 参数

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:14:06 24 4
gpt4 key购买 nike

我在 attrs.xml 中定义了一组自定义 Android 布局参数。现在我想在我的 styles.xml 文件中使用一些标签。

目前我得到这个错误:

error: Error: No resource found that matches the given name: attr 'custom:tag'

我试过如下声明自定义 XML 命名空间:

<resources
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res/com.my.project"
>

希望在每个布局声明中使用的相同逻辑可以在这里应用,但没有成功。

最佳答案

XML 命名空间机制用于命名标签和属性。当您定义这样的样式时:

<?xml version="1.0" encoding="utf-8"?>
<resources
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res/com.my.project">

<style name="my_style"> <item name="custom:tag">some_value</item> </style>

</resources>

您正在尝试将 XML 命名空间应用到属性,但这是行不通的。在这种情况下,您应该直接指定包名称,如下所示:

    <style name="my_style"> <item name="com.my.project:tag">some_value</item> </style>

现在 Android 将能够解析属性的定义位置。

关于android - styles.xml 中使用的自定义 attrs 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4265532/

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