简体   繁体   English

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

[英]Android - CirclePageIndicator with custom drawable

I'm using CirclePagerIndicator https://github.com/JakeWharton/ViewPagerIndicator but I need to customize whole paint object with an image resource. 我正在使用CirclePagerIndicator https://github.com/JakeWharton/ViewPagerIndicator,但是我需要使用图像资源自定义整个绘画对象。 One for selected page and another for not selected state. 一个用于选定页面,另一个用于未选定状态。 Now this library can only accept color. 现在,该库只能接受颜色。 Is there a way or alternative to do that? 有没有办法做到这一点?

this is what I'm trying to do: 这就是我想要做的:

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);

thanks. 谢谢。

EDIT 编辑

Since I have not found any solution around I decided to create my own library to do that, inspirated to Jake Wharton CirclePageIndicator. 由于尚未找到解决方案,因此我决定创建自己的库来实现这一点,这受到了Jake Wharton CirclePageIndicator的启发。 I post a link that should help all those who need it: 我发布了一个链接,该链接应该对所有需要它的人有所帮助:

https://github.com/augustopicciani/DrawablePageIndicator https://github.com/augustopicciani/DrawablePageIndicator

As you can see the style.xml file at the original source , it will show you customizable attributes. 如您在原始源代码中看到的style.xml文件 ,它将显示可自定义的属性。

To customize styles, apply attributes at the layout xml file as below. 要自定义样式,请在布局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>

Note that xmlns:app="http://schemas.android.com/apk/res-auto" is defined in order to utilize attributes at the styles.xml . 请注意,定义了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