java - How can I change color of button's background -


i have many buttons in calculator app. testing 1 button start, buttons id "one" , should change colour when click blue theme button. have tried following methods:

bluetheme = (button) findviewbyid(r.id.bluetheme); bluetheme.setonclicklistener(new onclicklistener() {      @override     public void onclick(view v) {          one.setbackgroundcolor(color.argb(175, 144, 202, 249));         one.setbackgroundcolor(color.parsecolor(/*hex code here*/));         one.setbackgroundcolor(color.blue);      }  });     

nothing seems anything. trying change colour of button in 1 activity via option in activity. here's actual button one:

one = (button) findviewbyid(r.id.one); one.setonclicklistener(new view.onclicklistener() {      @override     public void onclick(view v) {          result.append("1");     } }); 

xml code of one in activity_main.xml:

<button android:id="@+id/one"         android:layout_width="wrap_content"         android:layout_height="100dp"         android:layout_weight="1"         android:background="#cccccc"         android:text="1"         android:textcolor="#ff6600"         android:textsize="50sp"         android:layout_marginright="1dp"         android:layout_margintop="1dp"         android:layout_marginbottom="1dp" /> 

idea there option in intent can change colors of calculator, testing on 1 button fails, can't proceed. thank time.

the problem click 1 activity cant through other activity unless pass over.

in activity blue theme button

bluetheme.setonclicklistener(new onclicklistener() {      @override     public void onclick(view v) {         //note: i've put mainactivity should name         //      of whatever activity code nested in         intent intent = new intent(mainactivity.this, otheractivity.class); //use real class name         intent.putextra(otheractivity.extra_color, color.blue);         startactivity(intent);      }  });   

in otheractivity.class

public class otheractivity extends activity {      public static string extra_color = "extra_color";      public void oncreate(...) {          view 1 = (button) findviewbyid(r.id.one);          //note: if add singletop activity in manifest         //      might need on onnewintent          intent intent = getintent();         if (intent.hasextra(extra_color)) {             int color = intent.getintextra(extra_color, color.white);             one.setbackgroundcolor(color);         }      }  } 

Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -