溫馨提示×

Android按鈕如何設置陰影效果

小樊
200
2024-07-20 07:05:50
欄目: 編程語言

要在Android按鈕上添加陰影效果,可以使用如下方法:

  1. 在XML布局文件中設置按鈕的陰影效果:
<Button
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Button"
    android:background="@drawable/button_shadow"/>
  1. 創建一個名為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>
  1. 在Activity中設置按鈕的陰影效果:
Button button = findViewById(R.id.button);
button.setElevation(8f);

通過以上步驟,您可以在Android按鈕上添加陰影效果。您可以根據需要調整陰影的顏色、大小和位置來實現不同的效果。

0
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女