【问题标题】:the edge of a Button still has a light grey line around it while the edge of it has the same color of backgroundButton 的边缘周围仍然有一条浅灰色线,而它的边缘具有相同的背景颜色
【发布时间】:2019-10-12 21:53:12
【问题描述】:

我为按钮设置了渐变,颜色为红色,边缘颜色也为红色,
按钮也放置在红色的线性布局中

问题是按钮的边缘周围仍然有一条浅灰色线
为什么?
由于边缘是红色的,所以应该看不到边缘

如图所示,当边缘为绿色时,仍然可以看到灰色的东西

【问题讨论】:

  • 检查是否是按钮的阴影。
  • 发布布局和屏幕

标签: android gradient


【解决方案1】:

这是材料设计指南中按钮的默认阴影。要删除它,请将此属性放入您的 <Button 元素中:

    android:stateListAnimator="@null"

或者,以编程方式,您可以这样做:

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) { //Check if it's supported
    yourButton.setStateListAnimator(null);
}

【讨论】:

  • 这是一个动态按钮,我需要有问题地这样做
  • 好吧,灰边确实消失了,LOLLIPOP下面呢?
  • 下面的 Lollipop Buttons 没有默认的 stateListAnimator,所以应该没有问题
【解决方案2】:

您可以尝试将此代码添加到按钮的 xml 中

style="?android:attr/borderlessButtonStyle"

【讨论】:

    猜你喜欢
    • 2018-11-14
    • 2020-08-17
    • 1970-01-01
    • 2023-03-28
    • 2020-06-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多