5

カスタム属性スタイルを次のように作成しました

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

エラー: RelativeLayout ファイルで行ったのと同じ名前空間を配置しましたが、指定された名前の効果に一致するリソースが見つかりませんでした。

何か案は?ありがとう

4

2 に答える 2

23

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

于 2013-04-05T01:13:38.013 に答える