简体   繁体   中英

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. 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. I post a link that should help all those who need it:

https://github.com/augustopicciani/DrawablePageIndicator

As you can see the style.xml file at the original source , it will show you customizable attributes.

To customize styles, apply attributes at the layout xml file as below.

<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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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