0

Say I create a custom button like

<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#FFFFFF" />
<corners android:radius="5dp"/>

And in my layout file I use the rounded button as

<Button
    style="@style/login_button"
    android:background="@drawable/button_rounded"
    android:text="Awesome button"
/>

Is it possible to change the color of the button from the layout file? I just want a single rounded rectangular button, but want to be able to vary the background color if needed.

JohnB
  • 1,743
  • 5
  • 21
  • 40
  • http://stackoverflow.com/questions/20463082/change-the-shape-color-in-an-android-xml might help you – Dhinakaran Thennarasu Mar 16 '15 at 00:46
  • I came across this while searching around for an answer. However it seems this link, and all related links, indicate that changing the shape color needs to be done from the code? – JohnB Mar 16 '15 at 00:47
  • Yup. Whats the difference if you change it in res/layout or res/drawable/shape ? Better to do it runtime. or put it as constant in colors.xml and use it. – Dhinakaran Thennarasu Mar 16 '15 at 01:04
  • I could do it that way. I was just looking if there was a way to style it from the XML like can be done with some of the built in widgets – JohnB Mar 18 '15 at 03:10

0 Answers0