How to remove button shadow (android)

前端 未结 10 1853
失恋的感觉
失恋的感觉 2020-12-07 11:16

I want to remove the shadow from the button to make it seem more flat.

I have this right now:

\"cancel

相关标签:
10条回答
  • 2020-12-07 11:23

    Kotlin

    stateListAnimator = null
    

    Java

    setStateListAnimator(null);
    

    XML

    android:stateListAnimator="@null"
    
    0 讨论(0)
  • 2020-12-07 11:26

    Instead of a Button, you can use a TextView and add a click listener in the java code.

    I.e.

    in the activity layout xml:

    <TextView
        android:id="@+id/btn_text_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorPrimaryDark"
        android:text="@string/btn_text"
        android:gravity="center"
        android:textColor="@color/colorAccent"
        android:fontFamily="sans-serif-medium"
        android:textAllCaps="true" />
    

    in the activity java file:

    TextView btnTextView = (TextView) findViewById(R.id.btn_text_view);
    btnTextView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    // handler code
                }
            });
    
    0 讨论(0)
  • 2020-12-07 11:28

    Using this as the background for your button might help, change the color to your needs

    <?xml version="1.0" encoding="utf-8" ?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:state_pressed="true" >
            <shape android:shape="rectangle">
                <solid android:color="@color/app_theme_light" />
                <padding
                    android:left="8dp"
                    android:top="4dp"
                    android:right="8dp"
                    android:bottom="4dp" />
            </shape>
        </item>
        <item>
            <shape android:shape="rectangle">
                <solid android:color="@color/app_theme_dark" />
                <padding
                    android:left="8dp"
                    android:top="4dp"
                    android:right="8dp"
                    android:bottom="4dp" />
            </shape>
        </item>
    </selector>
    
    0 讨论(0)
  • 2020-12-07 11:33

    try : android:stateListAnimator="@null"

    0 讨论(0)
  • 2020-12-07 11:35

    A simpler way to do is adding this tag to your button:

    android:stateListAnimator="@null"
    

    though it requires API level 21 or more..

    0 讨论(0)
  • 2020-12-07 11:41

    Material desing buttons add to button xml: style="@style/Widget.MaterialComponents.Button.UnelevatedButton"

    0 讨论(0)
提交回复
热议问题