gpt4 book ai didi

android - 在 styles.xml 中使用自定义属性

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

我做了一个自定义属性样式为

<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="EffectsTextView">
<attr name="strokeWidth" format="float" />
<attr name="strokeMiter" format="float" />
<attr name="strokeColor" format="color" />
</declare-styleable>
</resources>

在布局文件中,我可以使用这个自定义属性为这个属性分配一个命名空间:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    
xmlns:effects="http://schemas.android.com/apk/res-auto/com.base.view.EffectsTextView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#40000000" >

<com.base.view.EffectsTextView
android:id="@+id/textView1"
android:layout_width="290dip"
android:layout_height="80dip"
android:layout_marginLeft="5dip"
android:layout_marginTop="16dip"
android:gravity="center"
android:text="SETTINGS"
android:textSize="44dip"
android:textStyle="bold"
effects:strokeWidth="10" /> <--- custom tag "effects"

但是它无法识别 styles.xml 中的这个自定义标签

<style name="EffectsHeaderTextStyle">
<item name="effects:strokeWidth">10</item>
</style>

错误:没有找到与给定名称、效果匹配的资源,尽管我将 namespace 与我在 RelativeLayout 文件中所做的相同。

有什么想法吗?谢谢

最佳答案

将您的 XML 更改为:

xmlns:effects="http://schemas.android.com/apk/res/com.base.view.EffectsTextView"

然后改变你的风格:

<style name="EffectsHeaderTextStyle">
<item name="strokeWidth">10</item>
</style>

我对字体做了类似的事情:

https://github.com/androidfu/CodeExamples/tree/master/com.androidfu.CustomFontsDemo

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

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