[英]Ripple effect for lollipop views
我一直在為Lollipop(API 21)開發一個應用程序。
當我將Button
顏色更改為某些內容時,漣漪效果不起作用。
我發現了一些第三方庫用於漣漪效應,但我想用標准API來做這件事。
這個答案也沒有幫助。
XML:
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="@+id/button"
android:layout_below="@+id/textView"
android:background="@android:color/holo_blue_bright"
android:layout_alignParentStart="true"
android:layout_marginTop="76dp"
/>
您必須將按鈕的背景設置為RippleDrawable,您可以使用XML定義它。 (我將它命名為holo_blue_ripple.xml
)
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@android:color/white"> <!-- ripple color -->
<item android:drawable="@android:color/holo_blue_bright"/> <!-- normal color -->
</ripple>
然后用android:background="@drawable/holo_blue_ripple"
引用它。
另外?attr/selectableItemBackgroundBorderless
可用於圓形波紋效果。
試試這個屬性
android:background="?attr/selectableItemBackground"
這是在視圖/布局中顯示漣漪效果的最簡單方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.