有人可以幫我我在 android 中使用按鈕,我無法更改按鈕顏色,這是我的 xml 代碼:
<Button
android:id="@ id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
tools:layout_editor_absoluteX="133dp"
tools:layout_editor_absoluteY="584dp" />
uj5u.com熱心網友回復:
使用屬性android:backgroundTint。例如:
<Button
android:id="@ id/button3"
<!-- ADD THE LINE BELOW -->
android:backgroundTint="@color/black"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
tools:layout_editor_absoluteX="133dp"
tools:layout_editor_absoluteY="584dp" />
如果看不到想要的顏色,請將其添加到colors.xml檔案夾中存盤的檔案中values。這是一個colors.xml檔案示例:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="black">#333333</color>
</resources>
你應該已經有了這個檔案,如果沒有,添加它。
uj5u.com熱心網友回復:
您可以使用材質按鈕,它不會影響按鈕的波紋和高度

<com.google.android.material.button.MaterialButton
android:layout_width="wrap_content"
app:backgroundTint=""ff0000"
android:text="Hello World"
android:layout_height="wrap_content" />
uj5u.com熱心網友回復:
以前對我有幫助的解決方案。查看您的 theme.xml 檔案。改成 android:theme="@style/Theme.AppCompat.NoActionBar"
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/433890.html
