When i say
button.setBackgroundColor(Color.BLUE);
the button shape changes to rectangle from default shape. I want to change the button color without affecting its original shape. Please help me.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Whenever you change the default background of your button the shape is going to change as the default shape is rectangle and the default background is a shape drawable with rounded corners. If you use any other background this rounded corner effect is lost.
You can achieve the same effect with any color or shape if you use a shape drawable as the background.
Here is how you can achieve this:
sample code for shape drawable:
If you want to have a button with a selector then use this xml as the background
This is a selector xml with items as the different shape drawables. If the button is pressed that is the button’s state is state_pressed then the top shape drawable is used else the bottom shape drawable is used.
I hope this will help.