0
<Button
    android:id="@+id/delete_set"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:backgroundTint="@color/white"
    android:drawableLeft="@drawable/ic_remove_routine"
    android:elevation="4dp"
    android:translationZ="3dp"
    android:stateListAnimator="@null"
    android:text="Remove Set"
    android:textSize="12dp"
    android:textColor="@color/orgin_text_color"
    android:clickable="true"
    android:layout_marginTop="10dp"
    android:layout_marginLeft="1dp"
    android:layout_marginRight="1dp"
    app:layout_constraintHorizontal_weight="1"/>
<Button
    android:id="@+id/add_set"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:backgroundTint="@color/white"
    android:drawableLeft="@drawable/ic_add_routine"
    android:text="ADD SET"
    android:textSize="12dp"
    android:elevation="4dp"
    android:translationZ="3dp"
    android:stateListAnimator="@null"
    android:textColor="@color/orgin_text_color"
    android:layout_marginTop="10dp"
    android:layout_marginLeft="1dp"
    android:layout_marginRight="1dp"
    app:layout_constraintHorizontal_weight="1"/>

enter image description here

The xml code and pictures are the UI I made.

I want to go ahead with this design.

I have referenced this link. Android elevation not showing shadow on Button

Q1. How can you give the button click effect in this situation?

I want to give the button an elevation effect.

Normally it didn't apply when using the elevation property.

So I used the android:stateListAnimator="@null" attribute. Works fine.

However, when I click, the button click effect does not appear.

The reason was the stateListAnimator property. When I delete this, the button click effect appears.

However, if i delete this, the depth of the elevation property cannot be adjusted.

So maybe I need this property for elavation.


Q2. When choosing a button color, what's the difference between background and backgroundTint?

When I first set the color of the button, I used the background="@color/white" property.

But the color has not changed.

In that link, obviously we use the background property for the button's color.

The case I use the background property of a button is when I use background="?android:selectableItemBackground" and background="#00ff0000".

These two properties make it completely transparent except for the text on the button.


Q3. Why doesn't background="@color/white" apply?

In connection with Q2, I am curious about why the color does not change when a color is specified with the background property.

ybybyb
  • 283
  • 1
  • 10
  • please don't ask multiple questions at once, it doesn't help people in future. stick to asking one question at a time or your question will be closed, then you find no answers either way – a_local_nobody Feb 22 '21 at 19:41

1 Answers1

1

first of all, it's not the best way to ask multiple questions at once! and for your questions, here's a hint :

  • Use a MaterialButton instead of a normal button:

    <com.google.android.material.button.MaterialButton android:layout_width="wrap_content" android:layout_height="wrap_content"/>

  • Visit this link for your second question