要在Android按钮上添加阴影效果,可以使用如下方法:
在XML布局文件中设置按钮的阴影效果:<Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" android:background="@drawable/button_shadow"/>创建一个名为button_shadow.xml的drawable资源文件,定义按钮的阴影效果:<shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="#FFFFFF"/> <corners android:radius="8dp"/> <padding android:left="8dp" android:top="8dp" android:right="8dp" android:bottom="8dp"/> <size android:width="200dp" android:height="60dp"/> <stroke android:width="1dp" android:color="#B3B3B3"/> <gradient android:startColor="#E5E5E5" android:endColor="#FFFFFF" android:angle="270"/></shape>在Activity中设置按钮的阴影效果:Button button = findViewById(R.id.button);button.setElevation(8f);通过以上步骤,您可以在Android按钮上添加阴影效果。您可以根据需要调整阴影的颜色、大小和位置来实现不同的效果。