Wednesday, March 5, 2014

Set color of Android button, programmatically

Here's a little problem that had Nirmal frustrated. If there is a layout with multiple buttons to switch layouts or views, how can the user be shown which layout he/she/ze is currently viewing? One idea: change the color of the text on the button which corresponds to the current layout. To do that is so easy!

Button whateverButton = (Button) findViewById(R.id.whateverButton);
whateverButton.setTextColor(Color.parseColor("#00a2ff")); //set text color

of course, you will need to import Button and Color if you haven't already, in Eclipse

1 comment: