Reputation: 331
I need to remove shadow from a button. Since it is created in java (not in xml) I can't see the option to do so. I know the following line can be used in xml.
android:stateListAnimator="@null"
Tried the same in java as follows.
myButton.setStateListAnimator(null);
But the problem is, it will work only on devices with 21 API or above. Is there any alternative way?
Upvotes: 2
Views: 1334
Reputation: 125
Use Button.setShadowLayer(float radius, float dx, float dy, int Color)
and set radius
to 0
.
Upvotes: 0
Reputation: 19351
put
android:background="@null"
I mean
myButton.setBackground(null);
EDIT: Other possibilities (sorry for xml):
Set elevation as 0:
mybutton.setElevation(0);
Set background as transparent:
android:background="@android:color/transparent"
Check: How to set transparent background for Image Button in code?
Set style to button:
<Button
...
style="?android:attr/borderlessButtonStyle"
....
/>
In Java code:
Button button = new Button(getApplicationContext(), null, android.R.attr
.borderlessButtonStyle);
button = (Button) findViewById(R.id.buttonEndTime);
You may also visit: Remove/add shadow effect dynamically
Upvotes: 3