我之前也曾與 android studio 合作過,并設計了自定義按鈕并用于應用,但最近我遇到了未應用顏色、形狀和角半徑已應用但顏色未應用的問題,它仍然是紫色。
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<corners android:radius="20dp"></corners>
<solid android:color="#11fa30"></solid>
</shape>
我已將此檔案保存在可繪制檔案夾中。我也將它應用到按鈕的背景
<Button
android:id="@ id/stop_rec"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textStyle="bold"
android:layout_margin="1dp"
android:background="@drawable/button_pressed"
android:text="@string/stop_r" />
正在應用形狀,但沒有應用顏色。有人可以指導我為什么面臨這個問題。
uj5u.com熱心網友回復:
將此行添加到按鈕的 xml 代碼中:
app:backgroundTint="@null"
uj5u.com熱心網友回復:
所以前幾天我只是嘗試了一些東西,我只能通過使用 androidx.appcompat.widget.AppCompatButton 而不是 normla Button 來更改按鈕背景和背景顏色。通過這種方式,您可以保持所有內容原樣,只需更改如下標簽:
<androidx.appcompat.widget.AppCompatButton
android:id="@ id/stop_rec"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textStyle="bold"
android:layout_margin="1dp"
android:background="@drawable/button_pressed"
android:text="@string/stop_r" />
我建議您使用一種更易于重用的樣式和一個可繪制的選擇器來管理“按下按鈕”狀態;)
如果您也想將該形狀用于其他視圖,但使用另一種顏色,您可以在 android:background="@drawable/button_pressed" 下方添加帶有您的顏色的背景色調。
我還注意到你有一個 layout_weight 沒有將寬度或高度更改為 0。也許你忘了洗掉它
希望我能幫上忙:)
uj5u.com熱心網友回復:
使用 UTF-8 對檔案進行編碼,如果它不起作用,請更改 colors.xml 中的顏色值
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="20dp"></corners>
<solid android:color="#11fa30"></solid>
</shape>
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/396209.html
上一篇:8年前1萬3安枕無憂,最后連7000的作業都找不到了?
下一篇:當我嘗試從ViewModel更改ModalBottomSheetState時,此CoroutineContext中沒有MonotonicFrameClock
