android - Programatically change the layout color of layout -


i trying programatically change layout color of relative layout (tried linear layout didn't change), cannot change it.

also trying debug app doesn't help, there not message related tag.

the application stood still after layout colored initially.

package com.test.intentdemo;  import android.app.activity; import android.graphics.color; import android.os.bundle; //import android.os.systemclock; import android.widget.relativelayout; import android.util.*; import java.lang.thread;  public class intentdemo extends activity {     /** called when activity first created. */     relativelayout llayout;     public static final string tag="myactivity";     @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.main);         llayout = (relativelayout) findviewbyid(r.layout.main);         if (log.isloggable(tag,0))         {             log.e(tag,"error before");             log.i(tag,"info before");             log.d(tag,"debug before");                  llayout.setbackgroundcolor(color.parsecolor("#000000"));                 //systemclock.sleep(2000);                 try                 {                 thread.currentthread();                 thread.sleep(2000);                 }                 catch (exception e)                 {                 //e.message();                 }               log.e(tag,"error after");             log.i(tag,"info after");             log.d(tag,"debug after");         }     } } 

any regarding helpful.

llayout = (relativelayout) findviewbyid(r.layout.main); 

this wrong. findviewbyid expects id of view. so, give id relativelayout, instance:

<relativelayout     android:id="@+id/the_id" 

then:

llayout = (relativelayout) findviewbyid(r.id.the_id); 

import android.app.activity; import android.graphics.color; import android.os.bundle; import android.widget.relativelayout;  public class intentdemo extends activity {     public static final string tag="myactivity";     @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.main);         relativelayout llayout = (relativelayout) findviewbyid(r.layout.the_id);         llayout.setbackgroundcolor(color.parsecolor("#000000"));     } } 

Comments

Popular posts from this blog

Javascript line number mapping -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -