How to set android button shadow instead of settin

2020-03-19 02:26发布

问题:

I'm trying to set a shadow for my button, but instead of getting shadow for the whole button I'm getting it for button's text only.

I've tried both: using xml styles

<style name="shadowed_button">
    <item name="android:shadowColor">#444444</item>
    <item name="android:shadowDx">1</item>
    <item name="android:shadowDy">1</item>
    <item name="android:shadowRadius">9</item>
</style>

and setting shadow programmatically

button.setShadowLayer(9, 1, 1, Color.rgb(44, 44, 44));

Both work identically. Does anyone know how to do this?

回答1:

To do so you have to make the image of the button with shadow and place on the button as drawable.