需求:最新开发,有几个渐变色的背景,因为图片比较大,为减小应用体积,用drawable资源文件来加载,然后代码转为Bitmap在设置背景。
实现:
1、drawable文件(色值随意定的,只是demo):
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<!--实现应用背景颜色渐变-->
<gradient
android:startColor="@color/colorAccent"
android:endColor="@color/colorPrimaryDark"
android:angle="270"/>
</shape>
2、代码中转Bitmap
private Bitmap getBitmapGradient(){
Drawable drawable = mContext.getResources().getDrawable(R.drawable.background_gradient);
GradientDrawable gradientDrawable