---
title: "[android]动态改变按钮背景状态 StateListDrawable"
author: "119568242"
date: "2012-10-29T10:52:14Z"
tags: []
categories: ["移动开发"]
slug: "android-statelistdrawable"
draft: false
lastmod: "2012-10-29T10:52:26Z"
id: 1707151
url: "https://poolo.iteye.com/blog/1707151"
---

动态改变按钮背景状态

 

很少用到 上次和六哥聊到。六哥有心 查了下  以下是DEMO

 

 

```
public static StateListDrawable setStateListDrawable(Context mActivity,
			int up, int down) {
		StateListDrawable stateListDrawable = new StateListDrawable();
		BitmapDrawable db = new BitmapDrawable(mActivity.getResources(),
				LoadImage.loadImage(mActivity.getResources(), down));
		stateListDrawable.addState(new int[] { android.R.attr.state_pressed },
				db);
		db = new BitmapDrawable(mActivity.getResources(), LoadImage.loadImage(
				mActivity.getResources(), up));
		stateListDrawable.addState(new int[] {}, db);
		return stateListDrawable;
	}
```