9

I've recently tried adopting a style-based approached to my android app. However, I'm stuck with this dilemma.

In my layout file I originally had this:

 <LinearLayout
         android:id="@+id/layout_event_buttons"
         style="?android:attr/buttonBarStyle"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_alignParentBottom="true"
         android:orientation="horizontal" >

         <ImageButton
             android:id="@+id/btn_create_event"
             style="?android:attr/buttonBarButtonStyle"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:contentDescription="@string/btn_save"
             android:src="@drawable/content_save"
             android:text="@string/btn_save" />
</LinearLayout>

In my styles.xml I tried doing this with no luck:

<style name="Buttons" parent="?android:attr/buttonBarButtonStyle">
    <item name="android:layout_width">match_parent</item>
    <item name="android:layout_height">wrap_content</item>
</style>

I already tried different variations of the above like:

?android:buttonBarButtonStyle

?attr:buttonBarButtonStyle

@android:attr/buttonBarButtonStyle

@android:buttonBarButtonStyle

I also tried:

<item name="style">?android:attr/buttonBarButtonStyle</item> 

to no avail.

My app won't compile because it can't find the buttonBarButtonStyle resource.

This is how I applied it. My other styles work fine if I just inherit the common themes like Holo, etc.

<ImageButton
     style="@style/Buttons"
     android:id="@+id/btn_create_event"
     android:contentDescription="@string/btn_save"
     android:src="@drawable/content_save"
     android:text="@string/btn_save" />
Chad
  • 738
  • 2
  • 8
  • 21
  • By the way, I have this in my manifest So I don't think I'm running it out of an unsupported api level. – Chad Sep 26 '13 at 06:47

3 Answers3

6

Found the answer to be similar to this post: How does an android:attr style work?

Turns out this style is private and you may need to copy it completely to be able to pull it off. :(

Community
  • 1
  • 1
Chad
  • 738
  • 2
  • 8
  • 21
0

I've found that applying android:background="?android:attr/selectableItemBackground" to the button attributes removes the borders, which makes the button act like the android buttonbar (after extending the ?android:attr/buttonBarButtonStyle as you have.

This post explains it well

Community
  • 1
  • 1
1owk3y
  • 1,115
  • 1
  • 15
  • 30
0

For AppCompat, you can inherit from the Parent style. For example, add this to each button.

<style name="MyBorderlessButtonBarStyle" parent="@style/Widget.AppCompat.Button.Borderless">

    <item name="android:layout_height">wrap_content</item>
    <item name="android:layout_width">0dp</item>
    <item name="android:textColor">@color/white</item>
    <item name="android:layout_weight">1</item>

    <!--more items-->

</style>
seekingStillness
  • 4,833
  • 5
  • 38
  • 68