繁体   English   中英

Android-具有自定义可绘制对象的CirclePageIndicator

[英]Android - CirclePageIndicator with custom drawable

我正在使用CirclePagerIndicator https://github.com/JakeWharton/ViewPagerIndicator,但是我需要使用图像资源自定义整个绘画对象。 一个用于选定页面,另一个用于未选定状态。 现在,该库只能接受颜色。 有没有办法做到这一点?

这就是我想要做的:

final float density = getResources().getDisplayMetrics().density;
circlePageIndicator.setStrokeWidth(2);
circlePageIndicator.setStrokeColor(getActivity().getResources().getColor(R.color.white)); //<== need resource image here not color
circlePageIndicator.setRadius(6 * density);

谢谢。

编辑

由于尚未找到解决方案,因此我决定创建自己的库来实现这一点,这受到了Jake Wharton CirclePageIndicator的启发。 我发布了一个链接,该链接应该对所有需要它的人有所帮助:

https://github.com/augustopicciani/DrawablePageIndicator

如您在原始源代码中看到的style.xml文件 ,它将显示可自定义的属性。

要自定义样式,请在布局xml文件中应用属性,如下所示。

<LinearLayout
    android:id="@+id/linearLayoutHeaderBanner"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <com.viewpagerindicator.CirclePageIndicator
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/circlePageIndicator"
        app:fillColor="#56b8e9"
        app:pageColor="#d2d2d2"
        app:radius="5dp"
        app:centered="true"
        app:strokeWidth="0dp"/>
</LinearLayout>

请注意,定义了xmlns:app="http://schemas.android.com/apk/res-auto"以便利用styles.xml属性。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM