Skip to content
This repository has been archived by the owner on Apr 19, 2018. It is now read-only.

Crash when using color values from styles. #424

Open
dmitvitalii opened this issue Aug 17, 2017 · 15 comments
Open

Crash when using color values from styles. #424

dmitvitalii opened this issue Aug 17, 2017 · 15 comments

Comments

@dmitvitalii
Copy link

I'm trying to set colors like that:

app:fillColor="?attr/colorAccent"
app:pageColor="?attr/colorPrimary"
app:strokeColor="?attr/colorPrimary"

It worked before, but now it throws:

android.view.InflateException: Binary XML file line #16: Binary XML file line #17: Error inflating class com.viewpagerindicator.CirclePageIndicator
caused by: java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x1d

I've tried to set @color/color_primary values and '#ff00ff' color hex values: the same issue.

As a workaround: I set all needed colors in runtime by calling setFillColor(), setPageColor() and setStrokeColor() respectively.

minSdkVersion 21
targetSdkVersion 26
buildToolsVersion "26.0.0"
@guillaume-tgl
Copy link

I have the same issue. It happened when I upgraded Gradle plugin to 3.0.0-beta4

@harry248
Copy link

Same here after updating project to new Android Plugin.

@janbolat
Copy link

Same here after updating to Android Studio 3 RC1, Gradle 4, Android Gradle plugin 3 rc2

@riadhnet
Copy link

@janbolat same here too

@toXel
Copy link

toXel commented Oct 21, 2017

Does anyone know a good alternative to this library? As it is no longer maintained I don't think we will get a fix for this anytime soon...

@javieramp
Copy link

Same too.
My solution is how it say dmitvitalii, removing --> app:fillColor="@color/blue"
and set it programmatically mIndicator.setFillColor(ContextCompat.getColor(context, R.color.blue));

@jannisveerkamp
Copy link

This Stackoverflow Answer worked well for me: https://stackoverflow.com/a/46950028/1350902

@VolodymyrMachekhin
Copy link

In my case, I had to set all app: attributes programmatically

@eriknyk
Copy link

eriknyk commented Nov 3, 2017

@jannisveerkamp question please,
did you added something else than: compile 'com.github.JakeWharton:ViewPagerIndicator:2.4.1' ?

because I'm getting an error

Error:(80, 13) Failed to resolve: com.github.JakeWharton:ViewPagerIndicator:2.4.1

@kotucz
Copy link

kotucz commented Nov 4, 2017

This is probably JitPack syntax
compile 'com.github.JakeWharton:ViewPagerIndicator:2.4.1'
you should add JitPack repository

repositories {
    maven { url "https://jitpack.io" }
}

but in my case it caused error somewhere else, so I solved this by setting the style programatically

@eriknyk
Copy link

eriknyk commented Nov 4, 2017

thank you @kotucz adding jitpack.io worked!

@lorenzopolidori
Copy link

lorenzopolidori commented Nov 7, 2017

compile 'com.github.JakeWharton:ViewPagerIndicator:2.4.1' using jitpack.io didn't work for me with the android gradle plugin 3.0.

Instead I had to set programmatically all the view attributes that I previously set in the xml layout with cpi: (or app:) attributes.

Example

<com.viewpagerindicator.CirclePageIndicator
    cpi:fillColor="@color/azure"
    cpi:pageColor="@color/white"
    cpi:radius="4dp"
    cpi:snap="true"
    cpi:strokeWidth="0dp" />

I removed all the cpi: attributes and set them all programmatically:

circlePageIndicator.setFillColor(ContextCompat.getColor(getContext(), R.color.azure));
circlePageIndicator.setPageColor(ContextCompat.getColor(getContext(), R.color.white));
circlePageIndicator.setRadius((int) (4 * Resources.getSystem().getDisplayMetrics().density));
circlePageIndicator.setSnap(true);
circlePageIndicator.setStrokeWidth(0);

See also https://stackoverflow.com/a/47163075/885464

@zhouchaoyuan
Copy link

zhouchaoyuan commented Nov 15, 2017

I get an exception on Android 7.1.1 :

java.lang.UnsupportedOperationException: Can't convert value at index 5 to color: type=0x5
                                                                      at android.content.res.TypedArray.getColor(TypedArray.java:463)
                                                                      at com.viewpagerindicator.CirclePageIndicator.<init>(CirclePageIndicator.java:96)
                                                                      at com.viewpagerindicator.CirclePageIndicator.<init>(CirclePageIndicator.java:72)
                                                                      at java.lang.reflect.Constructor.newInstance0(Native Methodat java.lang.reflect.Constructor.newInstance(Constructor.java:430at android.view.LayoutInflater.createView(LayoutInflater.java:645at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:787at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727at android.view.LayoutInflater.rInflate(LayoutInflater.java:858at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821at android.view.LayoutInflater.inflate(LayoutInflater.java:518at android.view.LayoutInflater.inflate(LayoutInflater.java:426at android.view.LayoutInflater.inflate(LayoutInflater.java:377at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139at com.sankuai.mhotel.GuideActivity.onCreate(GuideActivity.java:48at android.app.Activity.performCreate(Activity.java:6679at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726at android.app.ActivityThread.-wrap12(ActivityThread.javaat android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477at android.os.Handler.dispatchMessage(Handler.java:102at android.os.Looper.loop(Looper.java:154at android.app.ActivityThread.main(ActivityThread.java:6119at java.lang.reflect.Method.invoke(Native Methodat com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776

targetSdkVersion is 26
Is this a Compatibility problem?

@janbolat
Copy link

@zhouchaoyuan ,
you can read the answer here: https://stackoverflow.com/a/46950028/1350902

@zhouchaoyuan
Copy link

@janbolat , I have tried this before,it doesn't work for me.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests