簡體   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