如何在Android Lollipop中添加滚动视图边缘颜色效果? [英] How to add a scrollview edge color effect in Android Lollipop?

查看:149
本文介绍了如何在Android Lollipop中添加滚动视图边缘颜色效果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用中,我更改了过度滚动发光效果的颜色,如下所示:

In my app I change the overscroll glow effect color like this:

int glowDrawableId = contexto.getResources().getIdentifier("overscroll_glow", "drawable", "android");
Drawable androidGlow = contexto.getResources().getDrawable(glowDrawableId);
assert androidGlow != null;
androidGlow.setColorFilter(getResources().getColor(R.color.MyColor), PorterDuff.Mode.SRC_ATOP);

但是当我更新为棒棒糖时,此代码崩溃.我收到以下错误代码:

But when i updated to lollipop this code crashes. I get following error code:

FATAL EXCEPTION: main
Process: com.myproject.myapp, PID: 954
android.content.res.Resources$NotFoundException: Resource ID #0x0
at android.content.res.Resources.getValue(Resources.java:1233)
at android.content.res.Resources.getDrawable(Resources.java:756)
at android.content.res.Resources.getDrawable(Resources.java:724)

似乎棒棒糖中缺少overscroll_glow资源.

Seems that overscroll_glow resource is missing in lollipop.

我该如何实现?

推荐答案

您可以在主题中指定android:colorEdgeEffect,以更改整个应用程序中的过度滚动发光颜色.默认情况下,这继承了android:colorPrimary设置的原色值.

You can specify android:colorEdgeEffect in your theme to change the overscroll glow color within your entire app. By default, this inherits the primary color value set by android:colorPrimary.

res/values/themes.xml:

res/values/themes.xml:

<style name="MyAppTheme" parent="...">
    ...
    <item name="android:colorEdgeEffect">@color/my_color</item>
</style>

或者,您可以使用嵌入式主题叠加层为单个视图修改此值.

Alternatively, you can modify this value for a single view using an inline theme overlay.

res/values/themes.xml:

res/values/themes.xml:

<!-- Note that there is no parent style or additional attributes specified. -->
<style name="MyEdgeOverlayTheme">
    <item name="android:colorEdgeEffect">@color/my_color</item>
</style>

res/layout/my_layout.xml:

res/layout/my_layout.xml:

<ListView
    ...
    android:theme="@style/MyEdgeOverlayTheme" />

这篇关于如何在Android Lollipop中添加滚动视图边缘颜色效果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆