我在 Android Studio 中制作了一個圓形按鈕,因此對于圓形按鈕,我添加了一個新的 XML 檔案并將該檔案用作按鈕的背景。背景顏色默認是紫色,我想把它變成白色。我在 XML 中進行了更改(顏色現在設定為白色),但是,當我在設計中檢查它時,它仍然看起來是紫色的。
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/white" />
<stroke android:color="@color/white" android:width="1.5dp" />
<corners android:radius="25dp"/>
</shape>
Button Code:
<Button
android:id="@ id/button2"
android:layout_width="123dp"
android:layout_height="42dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:background="@drawable/rounded2"
android:backgroundTint="#F4F3F3"
android:text="Message"
android:textColor="#090808"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="@ id/textView3"
app:layout_constraintTop_toBottomOf="@ id/textView3" />
uj5u.com熱心網友回復:
使用以下代碼將材料庫添加到您的專案中:
implementation "com.google.android.material:material:1.4.0"
然后在您的視圖中將按鈕代碼更改為:
<com.google.android.material.button.MaterialButton
android:id="@ id/button2"
android:layout_width="123dp"
android:layout_height="42dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:backgroundTint="#F4F3F3"
android:text="Message"
android:textColor="#090808"
android:textSize="16sp"
app:cornerRadius="25dp"
app:layout_constraintEnd_toEndOf="@ id/textView3"
app:layout_constraintTop_toBottomOf="@ id/textView3" />
uj5u.com熱心網友回復:
您可以使用MaterialButton而不是Button
使用MaterialButton您可以使用屬性添加筆觸、背景顏色,MaterialButton而不是創建單獨的drawable檔案。
對于按鈕行程:
app:strokeWidth="1.5dp"
app:strokeColor="@color/white"
對于按鈕半徑:
app:cornerRadius="25dp"
對于按鈕背景:
app:backgroundTint="#F4F3F3"
材質按鈕代碼:
<com.google.android.material.button.MaterialButton
android:id="@ id/button2"
android:layout_width="123dp"
android:layout_height="42dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
app:backgroundTint="#F4F3F3"
app:strokeWidth="1.5dp"
app:strokeColor="@color/white"
app:cornerRadius="25dp"
android:text="Message"
android:textColor="#090808"
android:textSize="16sp"/>
uj5u.com熱心網友回復:
在 xml 檔案中使用 androidx.appcompat.widget.AppCompatButton 標簽而不是 Button。
<androidx.appcompat.widget.AppCompatButton
android:id="@ id/button2"
android:layout_width="123dp"
android:layout_height="42dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:background="@drawable/rounded2"
android:text="Message"
android:textColor="#090808"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="@ id/textView3"
app:layout_constraintTop_toBottomOf="@ id/textView3" />
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/430837.html
