Skip to content

Instantly share code, notes, and snippets.

@romannurik
Created April 10, 2012 04:24
Show Gist options
  • Star 63 You must be signed in to star a gist
  • Fork 18 You must be signed in to fork a gist
  • Save romannurik/2348305 to your computer and use it in GitHub Desktop.
Save romannurik/2348305 to your computer and use it in GitHub Desktop.
How to make a proper button bar on ICS
<!--
A button bar is a set of buttons at the bottom of an activity.
An example is an AlertDialog with OK/Cancel buttons.
Note that something similar can be accomplished using a
split action bar and text-only action buttons, but this is an
alternate presentation that's often preferred.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="?android:attr/dividerHorizontal"
android:showDividers="middle">
<TextView android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center"
android:text="Hello World" />
<LinearLayout style="?android:attr/buttonBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="One" />
<Button style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Two" />
</LinearLayout>
</LinearLayout>
@paour
Copy link

paour commented Apr 11, 2012

Roman, two issues in this code:

  • if the text in a button is too long to fit on a line, the alignment gets out of whack (this is also an issue in AlertDialog, on all versions of Android, very annoying)
  • on pre-ICS, the grey background isn't drawn

Please check my fork (gist:2357306) for an alternate version that fixes these.

@johnkil
Copy link

johnkil commented Apr 28, 2013

I made implementation for all android versions, check my fork

@LOG-TAG
Copy link

LOG-TAG commented Sep 11, 2014

@johnkil deleted the fork?

@GXYROX
Copy link

GXYROX commented Oct 18, 2014

@johnkil it's gone!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment