简体   繁体   English

Button 的边缘周围仍然有一条浅灰色线,而它的边缘具有相同的背景颜色

[英]the edge of a Button still has a light grey line around it while the edge of it has the same color of background

I set a Gradient for a Button with Color Red and edge Color of Red too,我为按钮设置了一个渐变,颜色为红色,边缘颜色为红色,
The Button is placed inside a Linear Layout with Red color too按钮也放置在红色的线性布局内

The problem is the edge of the Button still has a light grey line around it问题是 Button 的边缘周围仍然有一条浅灰色的线
Why?为什么?
Since the edge is Red there should be no edge seen由于边缘是红色的,所以应该看不到边缘

As is seen in the image, when edge is green still a grey thing is seen如图所示,当边缘为绿色时,仍然可以看到灰色的东西

在此处输入图像描述

It's the default shadow of button in material design guidelines.它是材料设计指南中按钮的默认阴影。 To remove it put this attribute in your <Button element:要删除它,请将此属性放在<Button元素中:

    android:stateListAnimator="@null"

Or, programmatically, you can do it in this way:或者,以编程方式,您可以这样做:

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

You can try to add this code to your button's xml您可以尝试将此代码添加到按钮的 xml

style="?android:attr/borderlessButtonStyle"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 android为白色时,为什么图像显示为浅灰色背景? - Why images are displayed with light grey background, when it has white android? Galaxy Nexus上的Android Theme.Holo.Light在模拟器没有的时候有灰色背景 - Android Theme.Holo.Light on Galaxy Nexus has grey background when emulator does not 当背景颜色较浅时,Android通知图标颜色不会更改为灰色 - Android notification icon color is not changed to grey when background color is light Android:如何在按钮周围放置边缘 - Android: How to place an edge around the button 如何阻止点击事件到三星S9 Edge按钮周围的DialogFragment背景 - How to block the click event to the background of DialogFragment around Samsung S9 Edge button AndroidX 在按钮上设置背景颜色没有效果 - AndroidX Setting Background Color on Button has NO Effect BottomNavigationView 中的选定项与背景颜色相同 - Selected Item in BottomNavigationView Has Same Color as Background 检查翻译视图是否已到达父级的边缘? - check if a Translating View has reached edge of parent? 在AsyncTasks仍在运行时检测是否已选择刷新按钮 - Detecting if a refresh button has been selected while AsyncTasks are still running 设置已经具有背景颜色的按钮边框 - setting button border which already has a background color
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM