嗨,所以我很困惑,想知道是否有人能指出我正确的方向.
在Lollipop和pre-lollipop上使用Google Play商店
您将在棒棒糖上看到可选择的视图具有涟漪效应.
在pre-lollipo上,你会获得这种高光效果.
这是怎么做到的?
在我的应用程序中,我有一个包含此选择器的drawable-v21目录
它基本上是在我的背景上产生涟漪
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?android:colorControlHighlight">
<item android:id="@android:id/mask" android:drawable="@android:color/white"/>
<item android:drawable="@color/colorAccentWith92PercentOpacity"/>
</ripple>
Run Code Online (Sandbox Code Playgroud)
但是,其他答案说要使用
机器人: "ATTR/selectableItemBackground" 背景=
要获得前棒棒糖的高光效果,但这会覆盖我的背景.我怎么能在我目前的背景之上设置它?
我还需要为我的应用程序中的每种按钮创建一个波纹drawable(在drawble-v21中)吗?我如何为回收商查看项目执行此操作?
是什么让这个问题与众不同
我不想要预先棒棒糖的涟漪我问的是开发者如何有效地使他们的按钮在棒棒糖上产生波纹并且对前的高光效果
我有一个CustomListView地方,我正在显示一些文本,并image使用Picasso的库显示.我在xmldrawable文件夹中创建了一个文件,并为drawable-21文件夹创建了一个文件,Ripple Effect但由于某种原因,效果不会超过ImageView.
这是我的文件:
drawable:
listview_item_background.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid
android:color="#ffdadada"/>
</shape>
</item>
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid
android:color="#ffffff"/>
</shape>
</item>
</selector>
Run Code Online (Sandbox Code Playgroud)
drawable-v21:
listview_item_background.xml
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#ffdadada">
<item android:drawable="@android:color/white"/>
</ripple>
Run Code Online (Sandbox Code Playgroud)
activity_main:
<?xml version="1.0"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="150dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:expandedTitleMarginStart="20dp"
app:expandedTitleMarginEnd="20dp"
app:contentScrim="@color/colorPrimary"
android:background="@color/colorPrimary"> …Run Code Online (Sandbox Code Playgroud) 我正在使用自定义波纹 drawable
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:exitFadeDuration="@android:integer/config_shortAnimTime"
android:color="@android:color/white">
<item android:id="@android:id/mask">
<shape android:shape="rectangle" >
<solid android:color="@android:color/white" />
</shape>
</item>
</ripple>
Run Code Online (Sandbox Code Playgroud)
但它崩溃了API 19上的应用程序
android.content.res.Resources$NotFoundException: File res / drawable /
ripple_effect_square2.xml from drawable resource ID #0x7f02017d
at android.content.res.Resources.loadDrawable(Resources.java:2101)
at android.content.res.Resources.getDrawable(Resources.java:700)
at android.view.View.setBackgroundResource(View.java:15303)
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line # 2: invalid drawable tag ripple
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java: 933)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java: 877)
at android.content.res.Resources.loadDrawable(Resources.java: 2097)
at android.content.res.Resources.getDrawable(Resources.java: 700)
at android.view.View.setBackgroundResource(View.java: 15303)
Run Code Online (Sandbox Code Playgroud)
我该怎么做才能防止崩溃?
我是Ripple的新手.我的问题是当我导入一个新项目并尝试使用ripple时,我在命令提示符中收到以下错误:
INFO: Server instance running on:http://localhost:4400
INFO: CORS XHR Proxy Service on: http://localhost:4400/ripple/xhr_proxy
INFO:JSONP XHR Proxy Service on: http://localhost:4400/ripple/jsonp_xhr_proxy
INFO: Could not find cordova as a local module.Expecting to find it installed Globally
Run Code Online (Sandbox Code Playgroud)
我通过命令行使用Ripple.当我在命令行中创建一个新项目时,我能够使用Ripple,但是当我尝试在新工作区中导入一个新项目并尝试使用波纹时,我收到上述错误消息..请建议做什么..请帮助....
是否可以创建一个RippleDrawable来定义无界纹波并同时背景颜色?我已经尝试了所有的东西,但是当我定义一个形状及其颜色时,纹波不再是无限的.此页面中还有https://developer.android.com/reference/android/graphics/drawable/RippleDrawable.html,没有关于在形状上添加无界纹波的参考.
我试过这个图层列表,但结果很糟糕
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<ripple
android:color="@color/android_l_light_gray">
</ripple>
</item>
<item>
<shape
android:shape="rectangle">
<solid android:color="@color/android_l_dark_gray" />
</shape>
</item> </layer-list>
Run Code Online (Sandbox Code Playgroud)
这就是我得到的 
我想在Android Lollipop的通知中为ImageView/ImageButton添加涟漪效果.我在Google Play音乐上看到了这种情况.但是,我在其他视图中使用的解决方案不适用于通知.
我在drawable-v21中创建了RippleDrawable
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#33000000">
</ripple>
Run Code Online (Sandbox Code Playgroud)
并将此drawable设置为ImageView的背景
<ImageView android:id="@+id/notification_play_button"
tools:src="@drawable/av_play_over_video"
android:layout_width="32dp"
android:layout_height="32dp"
android:background="@drawable/button_selector_semi_black"
/>
Run Code Online (Sandbox Code Playgroud)
但它根本行不通.你对如何实现这种效果有任何想法吗?
android android-notifications rippledrawable android-5.0-lollipop
我的应用程序中有一个按钮,我想为该按钮提供连续/无限的涟漪效果。如何在android中不点击的情况下在按钮上产生无限的涟漪效果。
我在RippleDrawable下面创建了一个喜欢。但是我无法更改 RippleDrawable 的圆角半径。它没有像setCornerRadii(float[] f).
public static RippleDrawable getPressedColorRippleDrawable(int normalColor, int pressedColor) {
if (Build.VERSION.SDK_INT>=21) {
RippleDrawable rippleDrawable = new RippleDrawable(getPressedColorSelector(normalColor, pressedColor), getColorDrawableFromColor(normalColor), null);
//rippleDrawable.setRadius((int) Manager.convertDpToPixel(5));
return rippleDrawable;
}
else
return null;
}
Run Code Online (Sandbox Code Playgroud)
其他功能是
public static ColorStateList getPressedColorSelector(int normalColor, int pressedColor) {
return new ColorStateList(
new int[][]
{
new int[]{android.R.attr.state_pressed},
new int[]{android.R.attr.state_focused},
new int[]{android.R.attr.state_activated},
new int[]{}
},
new int[]
{
pressedColor,
pressedColor,
pressedColor,
normalColor
}
);
}
public static ColorDrawable getColorDrawableFromColor(int color) {
return new ColorDrawable(color);
} …Run Code Online (Sandbox Code Playgroud) 我已经在 android 中实现了涟漪效应。使用以下代码:-
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#ff00ff00">
<item android:drawable="@android:color/black" />
</ripple>
Run Code Online (Sandbox Code Playgroud)
并将其设置为 textview 的背景
android:background="@drawable/ripple_over_drawable"
Run Code Online (Sandbox Code Playgroud)
但问题是波纹动画非常快。我想慢下来。
我目前正在实现一个应用程序,它有一个 RecyclerView,其中有几个自定义视图。从这些视图中的每一个,用户都可以打开一个上下文菜单(这需要长时间单击),但很难弄清楚,因为通常,他们只会执行一次简单的单击,然后认为没有什么其他的了。但如果我设法提供一些用户界面反馈,情况可能会更加清晰。这个想法是一个简单的波纹动画,突出显示背景,它不会通过简单的单击完成,但会一直持续长时间的单击操作。
因为我已经在这个问题上坚持了两天,所以我做了研究,实际上发现了一些同样的问题,例如Cheok Yan Cheng 的这个问题写得非常好,他甚至发布了一个视频,显示了预期的效果(我的问题几乎完全相同)但没有好的答案,因为第一个答案说我们应该使用,?attr/selectableItemBackground但给定的效果与我想要的效果不同,我尝试了第二个答案,它没有做任何事情在 onLongClick 中启动动画时进行简单的单击。
编辑 :
请注意,通过创建一个ripple xml 文件,然后将其设置为背景,无法实现预期的行为
?attr/selectableItemBackground,因为这将再次提供正常的 onClick 动画和与所需动画不同的 longClick 动画,请观看此视频以了解想要的效果是。