1

I have a Button that looks according to the Theme.Holo.Light. I used to round its corners by setting its background to the following:

   <?xml version="1.0" encoding="utf-8"?>
   <shape xmlns:android="http://schemas.android.com/apk/res/android"
   android:padding="10dp"
   android:shape="rectangle" >

   <corners
    android:bottomLeftRadius="15dp"
    android:bottomRightRadius="15dp"
    android:topLeftRadius="15dp"
    android:topRightRadius="15dp" />
   </shape>

Now the Button becomes transparent. I tried to create a selector, add a solid attribute and use 2 of such drawables for normal and pressed states, but I could not copy the default Button behavior of the Holo.Light theme. So I'm looking for 2 possible solutions: either somehow round the Button's corners without affecting its default Style or find the XML defining the mentioned style so I can copy it. I've been looking inside the SDK and using this reference: https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/res/res/values/themes.xml but did not succeed.

Any ideas how to make a rounded corners Button BUT keep all the other appearance attributes to their defaults?

azhar
  • 1,709
  • 1
  • 19
  • 41
Droidman
  • 11,485
  • 17
  • 93
  • 141
  • Maybe using some 9 patches would help. – Phantômaxx Feb 16 '14 at 16:21
  • @ArtooDetoo why? I don't need any custom backgrounds, I only need to round the corners of the button and keep all other things to their defaults – Droidman Feb 16 '14 at 16:23
  • The same reason why you tried using an xml drawable: to get round corners. – Phantômaxx Feb 16 '14 at 16:28
  • @ArtooDetoo I can round its corners, but the default background gets lots then. Using a 9 patch would result in exactly the same – Droidman Feb 16 '14 at 16:35
  • NO. A 9 patch doesn't have to be transparent. The original **style** (not theme, as erroneously linked in your question) uses 9 patches. If you read [THIS](https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/res/res/values/styles.xml) document and search for btn_default (beginning at line 1552), you will learn how to **make a style that overrides the standard drawables (9 patches)**. Then it's just a matter of copying the original artworks to your app's drawable folders and round their corners. – Phantômaxx Feb 16 '14 at 16:45
  • Begin from line 1995 (instead of 1552), to see the **light** variant. – Phantômaxx Feb 16 '14 at 16:53
  • ah ok, I have found the source for `btn_default_holo_light.xml` on GitHub, but I need to copy it into my project (so I can modify it) since that resource is not public and I can't reference it. Any idea where inside the SDK I can find that? – Droidman Feb 16 '14 at 17:15
  • check this solution http://stackoverflow.com/a/18879660/2337837 – Zied R. Feb 16 '14 at 17:21
  • If you're using Windows, it's here: **C:\Your_Path_To_Eclipse\sdk\platforms\android-XY\data\res\drawable**, where XY is 11 to 19 (depending on you minSdkVersion) – Phantômaxx Feb 16 '14 at 17:22
  • thx I found it, you can post your suggestions as an answer – Droidman Feb 16 '14 at 17:33
  • Yep, done! I tried to make it flow a little better. – Phantômaxx Feb 16 '14 at 17:42

1 Answers1

1

The original style uses 9 patches.
If you read THIS document and search for btn_default (beginning at line 1995), you will learn how to make a style that overrides the standard drawables (9 patches).
Then it's just a matter of copying the original artworks to your app's drawable folders and round their corners.

They'll be referred in a StateList drawable, called btn_default_holo_light.xml

If you're using Windows, it's here: C:\Your_Path_To_Eclipse\sdk\platforms\android-XY\data\res\drawable, where XY is 11 to 19 (depending on you minSdkVersion)

And the 9 patches here: C:\Your_Path_To_Eclipse\sdk\platforms\android-XY\data\res\drawable-RES, where XY is 11 to 19 (depending on you minSdkVersion) and RES is the specific dpi resolution (mdpi, as a reference)

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115