【Android】问题记录2015-11-11 13:50:16

来源:互联网 发布:app拍照软件排行 编辑:程序博客网 时间:2024/05/16 00:55

1.checkBox复写,改变图片
非常简单:继承checkbox后,复写setChecked中设置图片background就可以

public class DownloadGameCheckBox extends CheckBox {    public DownloadGameCheckBox(Context context) {        super(context);    }    public DownloadGameCheckBox(Context context, AttributeSet attrs) {        super(context, attrs);    }    public DownloadGameCheckBox(Context context, AttributeSet attrs, int defStyleAttr) {        super(context, attrs, defStyleAttr);    }    @Override    public void setChecked(boolean checked) {        if (checked) {            this.setBackgroundResource(R.mipmap.icon_data_select);        } else {            this.setBackgroundResource(R.mipmap.icon_data_unselect);        }        super.setChecked(checked);    }}

这样写需要在xml里配置属性:

        android:button="@color/transparent"

或者设置成@null,不过null在有些情况下回出现问题,不推荐使用
2.DownloadManager使用
链接
说明十分详细,给力的不行,不过是英文的
下载完成后自动安装:链接
当然,别忘了开权限:

<uses-permission        android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />
  1. selector的pressed、focused状态改变时图片随之改变
<selector xmlns:android="http://schemas.android.com/apk/res/android"><item android:state_focused="true" android:drawable="@drawable/your_imagename_while_focused"/><item android:state_pressed="true" android:drawable="@drawable/your_imagename_while_pressed" /><item android:drawable="@drawable/image_name_while_notpressed" />  //means normal</selector>

这个有代码方法、xml方法:链接

0 0
原创粉丝点击