0

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?

Ludo VdL
  • 11
  • 1

3 Answers3

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