14

I want to make my buttons style like the following enter image description here

I want to implement these buttons with my custom view I mean without using the AlertDialog

2 Answers2

52

If you prefer to use standard android attributes, see my answer here.

In short, for your buttons set style="?android:attr/buttonBarButtonStyle" and put them in a LinearLayout that has style="?android:attr/buttonBarStyle".

Community
  • 1
  • 1
hadi
  • 3,046
  • 1
  • 19
  • 11
  • 1
    This is the most correct answer. Attribute buttonBarButtonStyle is in holo theme (not sure about previous) set to borderlessButtonStyle which is what OP is after. +1 – Anderson Apr 29 '14 at 07:13
  • 1
    unfortunately this requires API 11. – AsafK Aug 19 '14 at 10:47
  • 5
    This does not look like the Alert Dialog. There are no dividers, above buttons or in middle of buttons – lostintranslation May 13 '15 at 22:41
  • 2
    I suggest dropping the `android:` to use the AppCompat styles. Not sure if they are any different from `?attr/buttonBarButtonStyle`, but there's also `?attr/buttonBarPositiveButtonStyle`, `?attr/buttonBarNeutralButtonStyle` and `?attr/buttonBarNegativeButtonStyle`. – 0101100101 Nov 13 '17 at 23:28
2

You can just do it with xml, like this:

Put this in drawable/border.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
   <solid android:color="#000000" />
   <stroke android:width="1dip" android:color="#333333"/>
</shape>

And then in your layout file:

<Button
    ...
    android:background="@drawable/border"
    android:textColor="#ffffff"
    android:textSize="13sp"
    ... />

Then you can just set your width & height to make it look great! :)

Edit: I would recommend to use this answer instead thought, much more better to use built-in Android-resources.

Community
  • 1
  • 1
GuiceU
  • 1,030
  • 6
  • 19
  • 35