stackoverflow 上有一些答案,但似乎都沒有幫助。我想要實作的不僅是透明背景,還有當單擊按鈕和邊框時發生的發光。
到目前為止我嘗試了什么:
android:background="?android:attr/selectableItemBackground"
結果(未單擊按鈕時):

結果(單擊按鈕時):

這基本上是我想要實作的,除了按鈕沒有邊框。
我試圖設定strokeColor,strokeWidth但沒有做任何事情。我仍然得到與上述相同的結果。
我也嘗試使用Material Outlined Button效果很好的樣式,但是當點擊按鈕開始作業時,我無法獲得發光效果。這基本上就像在 textView 中單擊一樣。
我能找到的最接近我的問題的答案是:Shaped drawable with selectableItemBackground as background
它完美地作業,除了邊框顏色。出于某種原因,它顯示的是 PURPLE(這是我的主色)而不是應有的黑色。
uj5u.com熱心網友回復:
如果您使用 Material Components 主題,并將 Material 輪廓按鈕樣式應用于按鈕,它將按照我認為您所描述的那樣顯示。
<Button
android:id="@ id/button"
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button" />
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/477353.html
