I'm creating a Dialog Box on Holo Theme and want to follow the OS default way of displaying the buttons. So far I have created the dialog box but the buttons don't render in the way it does in the apps done in Holo for ICS.
How can I do this?
My intended look & feel is
and I am able to reach till here

- 3,140
- 2
- 26
- 41
3 Answers
a bit late, but maybe someone is still interested in that.
this works pretty good for me.
...
<!--
EDIT: be carefull, "?android:attr/dividerHorizontal" is only supported since API 11
just avoid it in prior OSs.
-->
<View
android:layout_width="fill_parent"
android:layout_height="1dip"
android:background="?android:attr/dividerHorizontal" />
<LinearLayout
style="?android:attr/buttonBarStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="0dip"
android:paddingLeft="2dip"
android:paddingRight="2dip"
android:measureWithLargestChild="true">
<Button
android:id="@+id/cancel"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@android:string/cancel"/>
<Button
android:id="@+id/ok"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@android:string/ok"/>
</LinearLayout>
...
the activity that loads this layout needs the Holo.Dialog theme.
android:theme="@android:style/Theme.Holo.Dialog"

- 10,422
- 5
- 39
- 50

- 10,867
- 7
- 44
- 59
-
1Small correction: probably you should use dividerHorizontal in the very first view in your example. – dimsuz Jul 13 '13 at 10:01
-
1be carefull, dividerHorizontal isn't supported prior API 11. – Mario Lenci Dec 05 '13 at 10:19
-
@dimsuz Why the `dividerHorizontal`? – KevinOrr Mar 30 '14 at 01:14
-
@KevinOrr look at the screenshot in the question at the top: this is the divider which is above OK|Cancel buttons and it is a horizontal one. IIRC this answer had dividerVertical when first posted, but author has edited it since then and now everything's fine :) – dimsuz Mar 31 '14 at 20:38
-
@dimsuz I was trying it out in Eclipse and taking it out didn't seem to change anything. What's it doing? – KevinOrr Apr 12 '14 at 10:10
This is what works:
<LinearLayout
android:id="@+id/buttonHolder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<Button
android:id="@+id/cmdSignup"
style="@android:style/Widget.Holo.Light.Button.Borderless.Small"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/Signup" />
<Button
android:id="@+id/cmdLogin"
style="@android:style/Widget.Holo.Light.Button.Borderless.Small"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/Login" />
</LinearLayout>
The property style="@android:style/Widget.Holo.Light.Button.Borderless.Small"
gives the flat look and feel, and the 50% weight distribution is because of combining 100$ sizing of LinearLayout
by android:layout_width="match_parent" and
android:layout_weight="1"`for buttons

- 3,140
- 2
- 26
- 41
-
Thanks for the answer! Just wondering how or if you were able to get the light grey border around the buttons as shown in your first screenshot? Thanks – Dittimon Jun 21 '12 at 07:18
-
I didn't get it with this markup alone. I was in a rush.. very bad rush to complete the project and I didn't care to see why I didn't get it and I didn't correct it. In a weeks time, they asked to shift it from ICS to GB and I had to manually create all this so effort wasted and long forgotten :) – kishu27 Jun 22 '12 at 14:19
-
but yeah, if I had to do it again, I'd go to download one of the examples from Android Dev site and check it out – kishu27 Jun 22 '12 at 14:20
-
5You shouldn't be referencing the style directly, use `style="?android:attr/borderlessButtonStyle"` Which is used in the docs http://developer.android.com/guide/topics/ui/controls/button.html – smith324 Nov 23 '12 at 19:34
-
2This could be grate, but this requires API Level 14 for this style. Do you have solution if the backward compatibility matters? – Adorjan Princz Jul 26 '13 at 10:30
You can set the theme through the Android Manifest xml or inside the Activity's onCreate with setTheme(android.R.style.Theme_Holo);
The buttons size is not related to the theme itself. The size is up to your xml definitions. In the image you sent, it seems that the buttons received the Holo theme so there's nothing wrong here...
Here's an xml layout that will stretch the buttons to fill the whole dialog width:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
>
<Button
android:id="@+id/okButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="OK"
/>
<Button
android:id="@+id/cancelButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Cancel"
/>
</LinearLayout>
</LinearLayout>

- 26,213
- 16
- 65
- 114
-
I'm sorry but this doesn't work. I agree about the width, but I cannot get the flat look of the button on the dialog box – kishu27 Mar 21 '12 at 16:48
-
@kishu27 So the XML i wrote here fixed the buttons width but the buttons still don't get the Holo theme flat layout? – Lior Iluz Mar 21 '12 at 17:07
-
sadly not even the width :) I'm sorry.. I found out about the flat button style and will post the answer as soon as I fix the width issue. Strangely, your code should have worked but it isnt working and I can't think of anything else for the width – kishu27 Mar 21 '12 at 17:11
-
I think it the width worked fine as soon as I changed `fill_parent` to `match_parent` – kishu27 Mar 21 '12 at 17:24
-
1@kishu27 cool. at least my answer gave you the right direction :) glad you solve it. – Lior Iluz Mar 21 '12 at 17:26