How to programmatically set the button style – Android

How set rounded corners and own styles ActivityMy.java

Button btn.setBackgroundResource(R.drawable.back_button_answer);

\res\drawable\back_button_answer.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
   <corners android:radius="10dip" />
   <!-- background -->
 
   <gradient
                android:startColor="#D6D7D6"
                android:centerColor="#E2E2E2"
                android:centerY="0.75"
                android:endColor="#D6D7D6"
                android:angle="270"
        />
 
   <stroke android:width="2dip" android:color="#fff"/>
</shape>
This entry was posted in Android Examples Code and tagged , . Bookmark the permalink.


Comments are closed.



10,543 views