您好,登錄后才能下訂單哦!
在Android中實現(xiàn)Button的Ripple Effect可以通過使用Selector和Ripple Drawable來實現(xiàn)。以下是一個示例代碼示例:
res/drawable
目錄下創(chuàng)建一個button_ripple.xml
文件,定義Button的Ripple效果:<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?android:attr/colorControlHighlight">
<item android:id="@android:id/mask" android:drawable="@android:color/white" />
<item android:drawable="@drawable/button_bg" />
</ripple>
res/drawable
目錄下創(chuàng)建一個selector_button.xml
文件,定義Button的Selector效果:<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/button_ripple" />
<item android:drawable="@drawable/button_bg" />
</selector>
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/selector_button"
android:text="Button with Ripple Effect" />
這樣就可以實現(xiàn)一個帶有Ripple Effect的Button。當(dāng)用戶點擊Button時,會顯示出水波紋效果。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。