對按鈕的物質作用有背景顏色的我使用的是Android v21支持庫。我創建了一個自定義背景顏色的按鈕。當我使用背景顏色時,材質設計效果如波紋,顯示消失(除了點擊的高度)。 <Button
style="?android:attr/buttonStyleSmall"
android:background="?attr/colorPrimary"
android:textColor="@color/white"
android:textAllCaps="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button1"
/>以下是一個普通的按鈕,效果很好。<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAllCaps="true"
android:text="Button1"/>
3 回答

白衣非少年
TA貢獻1155條經驗 獲得超0個贊
另一個簡單的解決方案是為“平面”按鈕提供自定義背景,同時保持其“材質”效果。
將按鈕放在ViewGroup中,并在此處設置所需的背景
將當前主題中的selectableItemBackground設置為按鈕的背景(API> = 11)
即:
<FrameLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@color/blue"> <Button style="?android:attr/buttonStyleSmall" android:background="?android:attr/selectableItemBackground" android:textColor="@android:color/white" android:textAllCaps="true" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Button1" /></FrameLayout>
可以用于Flat按鈕,它適用于API> = 11,你將在> = 21設備上獲得連鎖效果,在21之前保持常規按鈕,直到AppCompat更新以支持那里的波紋。
您也可以僅對> = 21個按鈕使用selectableItemBackgroundBorderless。
另一個簡單的解決方案是為“平面”按鈕提供自定義背景,同時保持其“材質”效果。
將按鈕放在ViewGroup中,并在此處設置所需的背景
將當前主題中的selectableItemBackground設置為按鈕的背景(API> = 11)
即:
<FrameLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@color/blue"> <Button style="?android:attr/buttonStyleSmall" android:background="?android:attr/selectableItemBackground" android:textColor="@android:color/white" android:textAllCaps="true" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Button1" /></FrameLayout>
可以用于Flat按鈕,它適用于API> = 11,你將在> = 21設備上獲得連鎖效果,在21之前保持常規按鈕,直到AppCompat更新以支持那里的波紋。
您也可以僅對> = 21個按鈕使用selectableItemBackgroundBorderless。
- 3 回答
- 0 關注
- 396 瀏覽
添加回答
舉報
0/150
提交
取消