Android: programmatically created image vs resource image -


1) possible create drawable, example

static bitmap.config conf = bitmap.config.argb_8888; static bitmap bmp = bitmap.createbitmap(100, 100, conf); // draw // convert drawablebitmap 

and convert / asiggn / put in resource, use in function resource id param, like:

public void setwidgetlayoutresource (int widgetlayoutresid) 

or
2) possible dynamically draw change image in r.drawable.something.bmp?

all change color of widget in setwidgetlayoutresource() color, not fixed color of concrete resource

my own answer

this question relative other: android preferencescreen , in way:

colorlinesview.java

public class colorlinesview extends view {     private static gradientdrawable gddefault = new gradientdrawable();     public static int fillcolor;      public colorlinesview(context context, attributeset attrs)     {   super(context, attrs);     }      @override protected void ondraw(canvas cv)      {           gddefault.setcolor(fillcolor);        gddefault.setcornerradius(4);        gddefault.setstroke(2, 0xffbbbbbb);        this.setbackgrounddrawable(gddefault);     } } 

color_lines_accesory.xml

<?xml version="1.0" encoding="utf-8"?> <android.swp.colorlinesview xmlns:android="http://schemas.android.com/apk/res/android"  android:id="@+id/colorboxlines"  android:layout_width="52dp"  android:layout_height="26dp"  android:gravity="right"  android:layout_marginright="6dp" /> 

and while programmatically create preferencescreen, after add category preference "somepref":

colorlinesview.fillcolor = 0xff00ff00; // examply green somepref.setwidgetlayoutresource(r.layout.color_lines_accesory); 

and same 2 lines (with new color) in onpreferenceclicklistener() "somepref" category, after using color picker change color.

result:

enter image description here


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -