2015-10-20 64 views
1

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

这就是我想要做的事:

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

感谢。

编辑

因为我还没有找到任何解决办法左右,我决定创建自己的库来做到这一点,inspirated到杰克沃顿CirclePageIndicator。我发布一个链接,应该帮助那些谁需要它:

https://github.com/augustopicciani/DrawablePageIndicator

回答

0

正如你所看到的style.xml file at the original source,它会告诉你自定义的属性。

要自定义样式,请在布局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属性来定义。

+0

谢谢,我知道,但我需要在fillColor和pageColor中设置@ drawable/my_icon。不能使用颜色,因为图标有点复杂,并且它在状态选择和非选择之间应该有不同的笔划。 –

+0

@AugustoPicciani //这可能是痛苦。您可能需要定义您自己的可绘制属性。 – Youngjae

+0

好的,有一种方法可以通过程序从代码中设置笔画,这种代码会在选择状态和未选择状态时进行更改。 –