用shape画出的颜色做为背景。
android:dashWidth="1dp" android:dashGap="5dp" />
android:right="7dp" android:bottom="7dp" />
activity的xml文件
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:orientation="vertical" >
android:id="@+id/iv_change_color"
android:layout_width="match_parent"
android:layout_height="50dip"
android:background="@drawable/shape_2" />
android:id="@+id/seekbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:max="100" />
activity的代码。用seekbar来控制背景的颜色
setContentView(R.layout.shape_drawable_1);
mColorChangeValue = (mEndColor - mStartColor) / 100;
mSeekBar = (SeekBar) findViewById(R.id.seekbar);
mImageTest = (ImageView) findViewById(R.id.iv_change_color);
mGrad = (GradientDrawable) mImageTest.getBackground();
mSeekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
mGrad.setColor(mStartColor+mColorChangeValue * progress);
}
});
---------
---------
效果图