1

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 and button1 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

Sababado
  • 2,524
  • 5
  • 33
  • 51

1 Answers1

0

i guess the problem is in your activity Theme !!!!

its good to mention that the buttons takes their style from Activity THEME. what you can do is this:

  1. define a style :

    <style name="ThemeMaterialButtonColor" parent="Base.Widget.AppCompat.Button">
    <item name="colorButtonNormal">@color/md_teal_500</item></style>
    
  2. Then in your button in your xml add this :

    app:theme="@style/ThemeMaterialButtonColor"

Omid Heshmatinia
  • 5,089
  • 2
  • 35
  • 50