在android中的styles.xml中使用自定义attrs

ann*_*as8 5 xml android

我将自定义属性样式设为

<?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>
Run Code Online (Sandbox Code Playgroud)

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

<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"
Run Code Online (Sandbox Code Playgroud)

但是它没有在styles.xml中识别此自定义标记

<style name="EffectsHeaderTextStyle">
     <item name="effects:strokeWidth">10</item>
</style>
Run Code Online (Sandbox Code Playgroud)

错误:找不到与给定名称,效果匹配的资源,尽管我将命名空间与在RelativeLayout文件中的命名空间相同.

有任何想法吗?谢谢

Bil*_*ote 23

将您的XML更改为:

xmlns:effects="http://schemas.android.com/apk/res/com.base.view.EffectsTextView"
Run Code Online (Sandbox Code Playgroud)

并改变你的风格:

<style name="EffectsHeaderTextStyle">
    <item name="strokeWidth">10</item>
</style>
Run Code Online (Sandbox Code Playgroud)

我做了类似的字体:

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