Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
577 views
in Technique[技术] by (71.8m points)

android - How to remove border/shadow from lollipop buttons

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?

enter image description here

It might be more clear on this colored image. There is some kind of border around the buttons. enter image description here

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>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Lollipop has a nasty little feature called stateListAnimator which handles the elevations on Buttons, which leads to shadows.

Remove the stateListAnimator to get rid of the shadows.

You have got multiple options to do that:

Java:

button.setStateListAnimator(null);

Kotlin:

button.stateListAnimator = null

or in your layout xml's:

<Button
...
android:stateListAnimator="@null" 
....
/> 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...