use*_*901 14 android scrollview android-5.0-lollipop
在我的应用程序中,我更改过度滚动发光效果颜色,如下所示:
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);
Run Code Online (Sandbox Code Playgroud)
但当我更新到棒棒糖这个代码崩溃.我收到以下错误代码:
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)
Run Code Online (Sandbox Code Playgroud)
似乎棒棒糖中缺少overscroll_glow资源.我怎样才能在棒棒糖中实现这一目标?
提前致谢.
ala*_*anv 43
您可以android:colorEdgeEffect在主题中指定更改整个应用中的过卷发光颜色.默认情况下,这将继承由...设置的主要颜色值android:colorPrimary.
RES /值/的themes.xml:
<style name="MyAppTheme" parent="...">
...
<item name="android:colorEdgeEffect">@color/my_color</item>
</style>
Run Code Online (Sandbox Code Playgroud)
或者,您可以使用内联主题叠加层为单个视图修改此值.
RES /值/的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>
Run Code Online (Sandbox Code Playgroud)
RES /布局/ my_layout.xml:
<ListView
...
android:theme="@style/MyEdgeOverlayTheme" />
Run Code Online (Sandbox Code Playgroud)
该"android:colorEdgeEffect"解决方案完美无缺,并且比之前的黑客攻击更好.但是,如果需要以原始方式更改边缘颜色,则无法使用它.
这是可能的,但是,使用反射来做到这一点,设置EdgeEffect为直接对象AbsListView或ScrollView实例.例如:
EdgeEffect edgeEffectTop = new EdgeEffect(this);
edgeEffectTop.setColor(Color.RED);
EdgeEffect edgeEffectBottom = new EdgeEffect(this);
edgeEffectBottom.setColor(Color.RED);
try {
Field f1 = AbsListView.class.getDeclaredField("mEdgeGlowTop");
f1.setAccessible(true);
f1.set(listView, edgeEffectTop);
Field f2 = AbsListView.class.getDeclaredField("mEdgeGlowBottom");
f2.setAccessible(true);
f2.set(listView, edgeEffectBottom);
} catch (Exception e) {
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
EdgeEffect.setColor() 在Lollipop中添加了.
但是,与任何基于反射的解决方案相同.