Bruce He
Bruce He

Reputation: 27

How to referenced a theme style that defined in the library of ViewPagerIndicator?

I am using ViewPageIndicator through the build gradle. I felt theme provided in ViewPageIndicator style file were not suit my favor.

So I want to go to the Theme file destination to make some modifications hence it will fit my needs. However, Android Studio pop-up notice says that can't find declaration to go to.

Anyone knows how to fix it?

Upvotes: 0

Views: 216

Answers (2)

Bruce He
Bruce He

Reputation: 27

I just found out the answer to this question. We can use Android provided design tool to located any theme file that exists in our project. Firstly open any of a layout file and switch into the design view. Next, choose a theme layout you want to look, then click on the extract resource button to extract the resource and create a name for it. After it been done, you will see a style that you just named appears in your style file. But now, this style file still point at the original library files, so we are only able to look it but not allowed to make any modifications to it. As long as we able to read it, we can copy and paste it into somewhere else. So we should copy those inside codes to pasted a file that we created(File name can not be same as original file name). The solution is access all original file first then copy and paste it to the new file. Then referred your theme to the file you just created. And you are free to make modifications on your created files at any time and anywhere. enter image description here

Upvotes: 0

RenatoIvancic
RenatoIvancic

Reputation: 2092

I solved it with referencing the specific library styles in my custom app theme. If you look at source code of ViewPageIndicator you see the hooks where you can override indicator styles:

  • vpiIconPageIndicatorStyle
  • vpiCirclePageIndicatorStyle
  • ...

These are basic references to Widget style. For example for CirclePageIndicator you should extend Widget theme and link it to vpiCirclePageIndicatorStyle. Then you can set all the Widget properties and also custom CirclePageIndicator properties that you can find in attributes.

My theme file (styles.xml) regarding ViewPagerindicator:

<style name="BaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="vpiCirclePageIndicatorStyle">@style/Widget.CirclePageIndicator</item>
    ...
</style>

 <style name="Widget.CirclePageIndicator" parent="Widget">
    <item name="android:layout_marginBottom">10dp</item>
    <item name="android:layout_marginTop">5dp</item>
    <item name="android:padding">3dp</item>
    <item name="fillColor">@color/borders</item>
    <item name="gapWidth">@dimen/view_pager_circle_page_indicator_gap</item>
    <item name="radius">@dimen/view_pager_circle_page_indicator_radius</item>
    <item name="strokeColor">@color/borders</item>
    <item name="strokeWidth">@dimen/view_pager_circle_page_indicator_stroke</item>
</style>

And in layout xml, there is no need to specify style="@style/..." property.

<com.viewpagerindicator.CirclePageIndicator
      android:id="@+id/pagerIndicator"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"/>

The end result: enter image description here

Upvotes: 1

Related Questions