Using custom attrs in styles.xml in android

I created my own attribute style as

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

In the Layout file, I can use this custom attribute by assigning a namespace to this attribute:

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

However, it did not recognize this custom tag in styles.xml

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

Error: the resource was not found that matches the specified name, effects, although I set the namespace in the same way as in the RelativeLayout file.

Any ideas? Thanks

+4
source share
1 answer

Change your XML to:

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

And change your style:

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

I did something similar with fonts:

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

+20
source

All Articles