Skip to content

bug: android:background属性值为selector文件时报错 #77

@AweiLoveAndroid

Description

@AweiLoveAndroid

代码:

<ImageButton
            android:id="@+id/left_image2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/selector_test"
            android:layout_toRightOf="@id/left_textview"
            android:layout_centerVertical="true"
            android:layout_marginLeft="10dp" />

生成的内容:

ImageButton imageButton4 = new ImageButton(ctx);
        RelativeLayout.LayoutParams layoutParam4 = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT);
        imageButton4.setId(R.id.left_image2);
        imageButton4.setBackgroundResource(R.drawable.selector_test);
        layoutParam4.addRule(RelativeLayout.RIGHT_OF,R.id.left_textview);
        layoutParam4.addRule(RelativeLayout.CENTER_VERTICAL,RelativeLayout.TRUE);
        layoutParam4.leftMargin= (int)(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,10,res.getDisplayMetrics())) ;
        imageButton4.setLayoutParams(layoutParam4);
        relativeLayout1.addView(imageButton4);

这里 imageButton4.setBackgroundResource(R.drawable.selector_test); 把seulector资源刚在普通的图片资源了,这是不对的。

建议修复bug。

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions