[英]Problems with designing a custom view in Android studio
我正在遵循在android studio中創建自定義視圖的指南,該指南以XML定義視圖的屬性,但幾行導致類中的錯誤。 在導致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>
以下三行代碼
custom:circleColor="#6039ff"
custom:circleLabel="Hello"
custom:labelColor="#d9d908
在其中一個類中導致以下錯誤:
錯誤:(14)在程序包“ applicationprogramming.task401d”中找不到屬性“ circleColor”的資源標識符。
當我定義這些屬性時:獲取使用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);
我得到“無法解析符號”R。 解決此問題的唯一方法是刪除我定義屬性的位置。 任何幫助,將不勝感激。
提前致謝
您需要將自定義架構應用於xml。 如下使用。
<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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.