Android programmatically created textview setBackgroundResource not working in device -


code----

private textview setcontrolfordetails(textview a_tv_detail,         int ai_marginleft, int ai_margintop, int ai_width,         string as_detail, relativelayout a_rldetail,         int ai_backgroundresources)  {     string s_methodname = "setcontrolfordetails ";     try {           a_tv_detail = new textview(mainactivity.this);                      layoutparams layout_params = new layoutparams(ai_width, 50);          layout_params.leftmargin = ai_marginleft;          layout_params.topmargin = ai_margintop;         a_tv_detail.setlayoutparams(layout_params);         a_tv_detail.settext(as_detail);         a_tv_detail.setgravity(gravity.center);         a_tv_detail.settextcolor(getresources().getcolor(r.color.white));         a_tv_detail.settypeface(null, typeface.bold);         a_tv_detail.setbackgroundresource(getresources().getidentifier("header_bg", "drawable",getpackagename());                    a_rldetail.addview(a_tv_detail);     } catch (exception e) {         log.v(s_methodname, e.getmessage());         e.printstacktrace();     }     return a_tv_detail;  } 

xml ----

<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"     android:shape="rectangle" >      <stroke         android:width="5dp"         android:color="@color/border_color" />      <solid          android:color="@color/headerbg_color" >     </solid>      <padding         android:bottom="10dp"         android:left="10dp"         android:right="10dp"         android:top="10dp" />  </shape> 

try this

 a_tv_detail.setbackgroundresource(r.drawable.header_bg); 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -