I am trying to make a button that has a shadow using elevation with a background image being my sign in with gmail png. The button is contained within a relative layout. The elevation won't show no matter what I try to do. I tried solutions from other forum questions and none worked.
Here is my code for the button
<Button
android:id="@+id/google"
android:layout_width="270dp"
android:layout_height="38dp"
android:layout_marginTop="30dp"
android:layout_centerHorizontal="true"
android:background="@drawable/google"
android:elevation="10dp"
android:layout_below="@id/slogan"/>
The google drawable is a png image that I exported from Adobe XD. Could someone please give me a pointer on what I am doing wrong? Thanks.
Additionally, I realize that if I set the background of the button to android:color/white the shadow appears. So I think the issue is with the png drawable? Does elevation not work with png images? Is there a workaround?
Elevation: The static component. Translation: The dynamic component used for animations. Figure 1 - Shadows for different view elevations. To set the default (resting) elevation of a view, use the android:elevation attribute in the XML layout. To set the elevation of a view in the code of an activity, use the View.setElevation () method.
The elevation style property on Android does not work unless backgroundColor has been specified for the element. With backgroundColor applied to instructions element: Unless I'm missing something elevation should get applied regardless of whether a view has a background color or not. React Native version: 0.33 Platform (s) (iOS, Android, or both?):
The default Button style under Material has a StateListAnimator that controls the android:elevation and android:translationZ properties. just add this property to your Button. you can set your own using the android:stateListAnimator property. for Understanding I set it 10dp..
Android - elevation style property does not work without backgroundColor. · Issue #10411 · facebook/react-native · GitHub Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
For Material Button, I tried the following and it worked
android:translationZ="5dp"
Use below the line of code to show an elevation in button
android:outlineProvider="bounds"
– K. Sopheak
That works, thanks!
try this I hope it helps, because another view or layout just after your button is hiding shadow
android:layout_marginBottom="16dp"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With