ImageButton-设置background跟src

xml中添加ImageButton的background跟src

        <ImageButton
            android:id="@+id/tv3"
            android:layout_width="150dp"
            android:layout_height="150dp"
            android:layout_marginTop="20dp"
            android:src="@drawable/ic_alarm"
            android:background="#ff0000" />

 

代码中添加

        imagebutton.setBackgroundResource(R.drawable.ic_alarm);
        imagebutton.setImageResource(R.drawable.ic_alarm);

 如果要在代码中得到这两个drawable,我们可以用如下方法

//得到src
Drawable drawable = imageView.getDrawable();
//得到background
Drawable drawable2 = imageView.getBackground();

 

posted @ 2015-05-26 14:07  小白屋  阅读(673)  评论(0)    收藏  举报