Android App : Apply Color Theme Dynamically At Runtime
In My Application I want to support such functionality where users can select color from the list (which is downloaded from WebService) and as User selects any color(say Orange) al
Solution 1:
You could fill a Bitmap with a particular color.
private BitmapDrawable makeColorFillDrawable(int color, Drawable d) {
BitmapmaskBitmap= ((BitmapDrawable) d).getBitmap();
finalintwidth= maskBitmap.getWidth();
finalintheight= maskBitmap.getHeight();
maskBitmap = null;
finalBitmapoutBitmap= Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
finalCanvascanvas=newCanvas(outBitmap);
d.setBounds(0, 0, width, height);
d.setColorFilter(color, PorterDuff.Mode.SRC_IN);
d.draw(canvas);
d.setColorFilter(null);
d.setCallback(null);
returnnewBitmapDrawable(getResources(), outBitmap);
}
Save the color you fetch from your server in your SharedPreferences. Then subclass Button and apply the color fill drawable based on the value you saved. All you'd need to do then is replace <Button.../> in your XML with the path to your custom one.
Here's an example with the ActionBar icon.
finalDrawabled= getResources().getDrawable(android.R.drawable.sym_def_app_icon);
getActionBar().setIcon(makeColorFillDrawable(Color.RED, d));

Post a Comment for "Android App : Apply Color Theme Dynamically At Runtime"