Android examples for Graphics:Drawable Read
get GradientDrawable from resource id
//package com.java2s; import android.content.Context; import android.graphics.drawable.GradientDrawable; public class Main { public static GradientDrawable getDrawable(Context context, int ResId, int color, int width, int height) { GradientDrawable gradientDrawable = (GradientDrawable) context .getResources().getDrawable(ResId); gradientDrawable.setColor(color); if (width >= 0) { gradientDrawable.setSize(width, gradientDrawable.getIntrinsicHeight()); }//from w w w . j a v a 2 s . c o m if (height >= 0) { gradientDrawable.setSize(gradientDrawable.getIntrinsicWidth(), height); } return gradientDrawable; } }