I'm working on an Android project where the whole layout is created dynamically. Now I need to change the buttons to have rounded edges. So I can't do this in the xml but must do it in the code. Anyone knows how to do this?
Asked
Active
Viewed 480 times
0
-
Where is your code? – UmarZaii Aug 04 '17 at 23:52
-
Please see this first [how-to-ask](https://stackoverflow.com/help/how-to-ask) – always-a-learner Aug 05 '17 at 04:10
-
Possible duplicate of [How can I change a button style dynamically in Android?](https://stackoverflow.com/questions/4738309/how-can-i-change-a-button-style-dynamically-in-android) – David Rawson Aug 05 '17 at 10:59
3 Answers
0
Use
button.setBackgroundResource(R.drawable.custom_rouded_button_background);
custom_rouded_button_background.xml is defined in your drawable folder.

Kavach Chandra
- 770
- 1
- 10
- 25
0
You need a xml based drawable resource like this:
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" >
<stroke android:width="1dp"
android:color="#000000" />
<corners android:radius="5dp" />
<solid android:color="#FFFFFF" />
and change background of button. Make it to background.

Efe AYDIN
- 193
- 12
0
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners
android:topLeftRadius="0dp"
android:topRightRadius="0dp"
android:bottomLeftRadius="0dp"
android:bottomRightRadius="0dp"/>
<solid
android:color="#0C094F"/>
<size
android:width="dp"
android:height="62dp"/>
<stroke
android:width="3dp"
android:color="#878787"/>
</shape>

Harshit Trivedi
- 764
- 9
- 33