由视图扩展的自定义视图 class 的属性不起作用

properties of Custom view class extended by view are not working

我有一个名为 SingleTouchClass 的自定义 class,它由 View 扩展,我无法更改它的属性,例如背景颜色

    <com.pro.awais.pronoornotepad.SingleTouchClass
        android:id="@+id/canvas"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#000000"
        android:layout_weight="1" />

 **Here is simple empty SingleTouchClass just with a consturctor**


public class SingleTouchClass extends View {
    public SingleTouchClass(Context context, AttributeSet attrs) {
    super(context, attrs);
    }
 }

我只是个白痴....问题出在我的 signletouch class 中,我在 OnDraw 方法中绘制了类似 #ffffff 的颜色,这就是为什么对我没有任何作用的原因

你的代码是正确的,它会工作正常,因为我用我的包名尝试你的代码,它会显示黑色背景。

看我的代码只改变包名。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <com.example.addbuttondynamic.SingleTouchClass
        android:id="@+id/canvas"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#000000"
        android:layout_weight="1" />

</LinearLayout>

这是我的 SingleTouchClass.java

package com.example.addbuttondynamic;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;

public class SingleTouchClass extends View{

    public SingleTouchClass(Context context, AttributeSet attrs) {
        super(context, attrs);
        // TODO Auto-generated constructor stub
    }

}