3

I have been looking around for an easy way to make all buttons in my entire app have rounded corners.

I haven't succeeded, so I thought I'd ask =)

My AndroidManifest.xml:

<application android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@style/BlackTheme" android:alwaysRetainTaskState="true" android:name="MyApplication">

My styles.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="ButtonHeader" parent="@android:style/Widget.Button">
        <item name="android:textSize">18dip</item>
        <item name="android:minWidth">70dip</item>
        <item name="android:minHeight">20dip</item>
        <item name="android:maxHeight">30dip</item>
    </style>

    <style name="JobViewHeader" parent="@android:style/TextAppearance.Small">
        <item name="android:textStyle">bold</item>
        <item name="android:textColor">#FFFFFF</item>
        <item name="android:layout_width">wrap_content</item>
        <item name="android:layout_height">wrap_content</item>
    </style>

    <style name="BlackTheme" parent="@android:style/Theme.Black">
        <item name="android:button">@drawable/button_rounded</item>
    </style>  

    <style name="DialogTheme" parent="@android:style/Theme.Dialog">
    </style>  
</resources>

My button_rounded.xml (in drawables):

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <corners android:radius="10dp" /> 
</shape> 
Ted
  • 19,727
  • 35
  • 96
  • 154
  • You could change them all to `ImageButtons` and use a 9-patched drawable of a rounded corner box made in PowerPoint. :) – cornbread ninja Oct 20 '11 at 15:41
  • So, what problem you are getting? – Lalit Poptani Oct 20 '11 at 15:47
  • @LalitPoptani THe problem is that the buttons are unchanged, they are not rounded at all. – Ted Oct 20 '11 at 16:10
  • @cornbreadninja Nah, no 9-patches please. Thats a horrible way to work... should work with the radius on corners, somehow... – Ted Oct 20 '11 at 16:11
  • Check this though this is for editText http://stackoverflow.com/questions/3646415/how-to-create-edittext-with-rounded-corners/3646629#3646629 – Lalit Poptani Oct 20 '11 at 16:26
  • @Ted, at the risk of veering off into discussion-land, why do you feel it's a horrible way to work? draw-9 patch is a system utility. – cornbread ninja Oct 20 '11 at 16:37
  • @cornbreadninja Because you need to create the damn images, which is extremely time-consuming and messy. I prefer just changing a few characters in an XML file, and thats it. To create images, for something this easy, is just way to much overhead. – Ted Oct 20 '11 at 17:26

1 Answers1

0

As I understand, you are trying to specify some abstract drawable (Shape Drawable in your case) as a button background, which will be combined later with any other drawable set as a button background. Unfortunately, this is impossible. If you want a background with rounded corners, you need to provide drawable resource which does contain rounded corners, no matter what type of drawable it is: Shape Drawable, nine-patch, etc.

However you may consider subclassing the Button widget and overriding its draw method, where you can manipulate button's look as you wish.

a.ch.
  • 8,285
  • 5
  • 40
  • 53
  • Hmmm, so setting the background to a drawable with rounded corners would work? Maybe even something like: http://stackoverflow.com/a/3646629/175830 ? – Jason Axelson Mar 20 '12 at 01:03
  • Yes, why not? Use Shape Drawable, for example: ` ` And set it as a button's background. – a.ch. Mar 20 '12 at 07:45
  • Ok, that should work as long as I can still get the button depressed visual and everything. – Jason Axelson Mar 20 '12 at 20:44