I'm following a guide to creating a custom view in android studio whereby I define the view's attributes in XML but a few lines are causing errors in the classes. Here in the block of code causing troube:
<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>
The three lines of code bellow
custom:circleColor="#6039ff"
custom:circleLabel="Hello"
custom:labelColor="#d9d908
are causing the following error in one of the classes:
Error:(14) No resource identifier found for attribute 'circleColor' in package 'applicationprogramming.task401d'.
When I define these attributes: to get the text and colors specified using the names in 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);
I get 'Cannot resolve Symbol 'R. And the only way to solve this issue is to remove where i define the attributes. Any help would be appreciated.
Thanks in advance
You need to apply custom schema to xml. Use it like below .
<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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.