你可以設置EdgeEffect
顏色ViewPager
的一些反思:
public static void setEdgeGlowColor(ViewPager viewPager, int color) {
try {
Class<?> clazz = ViewPager.class;
for (String name : new String[] {
"mLeftEdge", "mRightEdge"
}) {
Field field = clazz.getDeclaredField(name);
field.setAccessible(true);
Object edge = field.get(viewPager); // android.support.v4.widget.EdgeEffectCompat
Field fEdgeEffect = edge.getClass().getDeclaredField("mEdgeEffect");
fEdgeEffect.setAccessible(true);
setEdgeEffectColor((EdgeEffect) fEdgeEffect.get(edge), color);
}
} catch (Exception ignored) {
}
}
public static void setEdgeEffectColor(EdgeEffect edgeEffect, int color) {
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
edgeEffect.setColor(color);
return;
}
Field edgeField = EdgeEffect.class.getDeclaredField("mEdge");
Field glowField = EdgeEffect.class.getDeclaredField("mGlow");
edgeField.setAccessible(true);
glowField.setAccessible(true);
Drawable mEdge = (Drawable) edgeField.get(edgeEffect);
Drawable mGlow = (Drawable) glowField.get(edgeEffect);
mEdge.setColorFilter(color, PorterDuff.Mode.SRC_IN);
mGlow.setColorFilter(color, PorterDuff.Mode.SRC_IN);
mEdge.setCallback(null); // free up any references
mGlow.setCallback(null); // free up any references
} catch (Exception ignored) {
}
}
我想你也需要讓自己的ViewPager類的副本,並使其ü選擇您的EdgeEffect對象而不是系統。 – FoamyGuy 2013-02-18 16:34:06
好了,但如果我這樣做,我得到一個敏捷裝載機錯誤:多DEX文件定義Landroid /支持/ V4 /視圖/ ViewPager $裝飾; – 2013-02-18 16:39:43
你需要把你的包裝放在你自己的包裏。和你的XML內引用它像' ' –
FoamyGuy
2013-02-18 16:41:06