I have a few dozen buttons in my app and a style that inherits from Widget.AppCompat.Button
. Most of the buttons have an elevation and state change animation. Awesome.
What isn't awesome is that a few of the buttons don't have anything of that extra goodness.
Here's an example of one of the working buttons
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="?attr/defaultPadding"
android:minHeight="?attr/minTouchSize"
android:textAppearance="?attr/textAppearanceListRowLabel" />
Here's a snippet from where the buttons do NOT work
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_weight="1"
android:minHeight="?attr/minTouchSize" />
<Button
android:id="@+id/button3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:minHeight="?attr/minTouchSize" />
</LinearLayout>
These are on separate layouts. Things I've tried:
- I've added
button1
to be in the same layout file as the button bar andbutton1
still works. - If I remove the weights from one of the buttons in the bar they don't work.
- I've tried explicitly putting my button style on each button
- If I make the button bar a vertical layout and make the buttons match parent then it works! But that isn't what I want.
I want to make these buttons have state animation and elevation while in a horizontal layout. Aka I want the buttons to take up equal space and sit next two each other. How can I achieve this?
I'm using appcompat 22.2.1