2017-11-27 6 views
0

アンドロイドスタジオでカスタムビューを作成するためのガイドに従って、ビューの属性をXMLで定義しますが、いくつかの行でクラスにエラーが発生しています。ここで、コードのブロックで引き起こすtroube:Androidスタジオでカスタムビューをデザインする際の問題

custom:circleColor="#6039ff" 
custom:circleLabel="Hello" 
custom:labelColor="#d9d908 

蛇腹コードの

<applicationprogramming.task401d.CustomView 
    android:id="@+id/custView1" 
    android:layout_width="0dp" 
    android:layout_height="0dp" 
    android:layout_margin="5dp" 
    custom:circleColor="#6039ff" 
    custom:circleLabel="Hello" 
    custom:labelColor="#d9d908"> 
</applicationprogramming.task401d.CustomView> 

3行は、クラスのいずれかで次のエラーが原因となっている。

Error:(14) No resource identifier found for attribute 'circleColor' in package 'applicationprogramming.task401d'.

Iが定義する場合これらの属性: attrs.xmlの名前を使用して指定されたテキストと色を取得する

circleText = a.getString(R.styleable.CustomView_circleLabel); 
circleCol = a.getInteger(R.styleable.CustomView_circleColor, 0);//0 is default 
labelCol = a.getInteger(R.styleable.CustomView_labelColor, 0); 

「シンボルを解決できません」というメッセージが表示されます。 この問題を解決する唯一の方法は、属性を定義する場所を削除することです。 ご協力いただければ幸いです。あなたがXMLにカスタムスキーマを適用する必要があり、事前

+0

は、それがファイルの先頭にタグを持っている必要があります、あなたはattrs.xmlファイルを投稿してください –

+0

styleable xmlファイルでこれを定義しました –

答えて

0

感謝。以下のように使用してください。

<applicationprogramming.task401d.CustomView 
    xmlns:custom="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/custView1" 
    android:layout_width="0dp" 
    android:layout_height="0dp" 
    android:layout_margin="5dp" 
    custom:circleColor="#6039ff" 
    custom:circleLabel="Hello" 
    custom:labelColor="#d9d908"></applicationprogramming.task401d.CustomView> 
関連する問題