如何从棒棒糖按钮中删除边框/阴影 [英] How to remove border/shadow from lollipop buttons
问题描述
对于 api < 按钮看起来不错21. 但是,+21 版本会创建此边框或阴影,如下图所示.如何在不改变孔主题的情况下摆脱它,但设置样式变量?
The buttons looks fine for api < 21. However, the +21 versions creates this border or shadow that is shown on the image below. How do I get rid of it without changeing the hole theme, but setting a style variable?
这张彩色图片可能更清晰.按钮周围有某种边框.
It might be more clear on this colored image. There is some kind of border around the buttons.
我的按钮样式定义如下:
My buttonssstyle is defined like this:
<style name="buttonTransparent" parent="Base.TextAppearance.AppCompat.Button">
<item name="android:background">#00000000</item>
<item name="android:textColor">@drawable/button_text_blue</item>
<item name="android:textSize">18dp</item>
<item name="android:textAllCaps">false</item>
<item name="android:minHeight">45dp</item>
</style>
<style name="buttonLargeWhite" parent="buttonTransparent">
<item name="android:background">#FFF</item>
<item name="android:layout_marginTop">10dp</item>
</style>
推荐答案
Lollipop 有一个叫做 stateListAnimator
的讨厌的小功能,它处理按钮上的高度,这会导致阴影.
Lollipop has a nasty little feature called stateListAnimator
which handles the elevations on Buttons, which leads to shadows.
移除 stateListAnimator
以去除阴影.
您有多种选择可以做到这一点:
You have got multiple options to do that:
Java:
button.setStateListAnimator(null);
科特林:
button.stateListAnimator = null
或在您的布局 xml 中:
<Button
...
android:stateListAnimator="@null"
....
/>
这篇关于如何从棒棒糖按钮中删除边框/阴影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!