亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

對按鈕的物質作用有背景顏色的

對按鈕的物質作用有背景顏色的

千萬里不及你 2019-07-27 15:27:13
對按鈕的物質作用有背景顏色的我使用的是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個贊

另一個簡單的解決方案是為“平面”按鈕提供自定義背景,同時保持其“材質”效果。

  1. 將按鈕放在ViewGroup中,并在此處設置所需的背景

  2. 將當前主題中的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。

另一個簡單的解決方案是為“平面”按鈕提供自定義背景,同時保持其“材質”效果。

  1. 將按鈕放在ViewGroup中,并在此處設置所需的背景

  2. 將當前主題中的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。


查看完整回答
反對 回復 2019-07-27
  • 3 回答
  • 0 關注
  • 396 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號