【问题标题】:Removing the shadow on button click删除按钮单击时的阴影
【发布时间】:2018-05-21 05:55:25
【问题描述】:

我在我的应用程序中创建了一个按钮列表,并将背景设置为椭圆形。在按下每个按钮时,我看到一个矩形形状的阴影,如何去除阴影。

请查看下面的截图:

这是 XML 中的按钮:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/buttonLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="10dp"
    android:visibility="visible">

    <android.support.v7.widget.AppCompatButton
        android:id="@+id/buttons"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:drawableLeft="@drawable/ic_compose"
        android:background="@drawable/roundedbutton"
        android:text="@string/ver"
        android:textSize="20sp"
        android:textColor="@color/blacktext" />

</LinearLayout>

圆形按钮可绘制:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient android:startColor="#FFFFFF"
        android:endColor="@color/white"
        android:angle="270" />
    <corners android:radius="55dp" />
    <stroke android:width="5px" android:color="@color/buttoncolor" />
</shape>

【问题讨论】:

  • 使用&lt;solid&gt;标签并将背景颜色设为白色。
  • 请您尝试使用Button 代替android.support.v7.widget.AppCompatButton。

标签: android


【解决方案1】:

将此添加到按钮样式:

shadowOffset: { height: 0, width: 0 },
shadowOpacity: 0,
elevation:0

它应该移除 android 上的按钮阴影

【讨论】:

    【解决方案2】:

    你需要给你的背景添加一个选择器,像这样

    <item android:state_selected="true">
    // if you want to change the color or any thing on press of the button, do that here
        <shape 
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:shape="rectangle">
            <gradient android:startColor="#FFFFFF"
                android:endColor="@color/white"
                android:angle="270" />
            <corners android:radius="55dp" />
            <stroke android:width="5px" android:color="@color/buttoncolor" />
        </shape>
    </item>
    
    <item >
        <shape xmlns:android="http://schemas.android.com/apk/res/android"
            android:shape="rectangle">
            <gradient android:startColor="#FFFFFF"
                android:endColor="@color/white"
                android:angle="270" />
            <corners android:radius="55dp" />
            <stroke android:width="5px" android:color="@color/buttoncolor" />
        </shape>
    </item>
    

    【讨论】:

      【解决方案3】:

      在你的按钮中试试这个

      android:stateListAnimator="@null"
      

      但android:stateListAnimator 是用于 api >= 21。如果你的 min sdk ,你可以使用

      style="?android:attr/borderlessButtonStyle"
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-01-01
        • 2015-04-29
        • 2022-01-21
        • 1970-01-01
        • 2015-03-08
        • 2014-08-05
        • 1970-01-01
        • 2021-04-16
        相关资源
        最近更新 更多