【问题标题】:properties of Custom view class extended by view are not working由视图扩展的自定义视图类的属性不起作用
【发布时间】:2015-09-18 21:22:28
【问题描述】:

我有一个名为 SingleTouchClass 的自定义类,它由 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);
    }
 }

【问题讨论】:

    标签: java android android-view android-custom-view


    【解决方案1】:

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

    查看我的代码仅更改包名称。

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

    【讨论】:

    • 那段代码没有任何问题......我已经在下面自己回答了我的问题......感谢您尝试我的一段代码:)
    【解决方案2】:

    我只是个白痴....问题出在我的 signletouch 类中,我在 OnDraw 方法中绘制 #ffffff 之类的颜色,这就是为什么对我没有任何效果

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-02
      • 1970-01-01
      • 1970-01-01
      • 2019-04-11
      • 2013-04-10
      相关资源
      最近更新 更多