android-target-tooltip
android-target-tooltip copied to clipboard
getColor throws exception -> Target SDK 23
In the TooltipTextDrawable Class line 42 thows an exception
int backgroundColor = theme.getColor(styleable.TooltipLayout_ttlm_backgroundColor, 0);
It looks like an issue by not using the ContextCompat Class
This is the code I use to create the Tooltip
Tooltip.make(_ctx, new Tooltip.Builder(101)
.anchor(this, Tooltip.Gravity.CENTER)
.closePolicy(new Tooltip.ClosePolicy().insidePolicy(true,true).outsidePolicy(true,true),3000)
.activateDelay(800)
.showDelay(300)
.maxWidth(300)
.floatingAnimation(Tooltip.AnimationBuilder.DEFAULT)
.text(getBubbleText())
.withArrow(true)
.withOverlay(true)
.build()).show();
04-04 16:20:41.200 16638-16638/com.bansi.pagomovil E/InputEventReceiver: Exception dispatching input event.
04-04 16:20:41.200 16638-16638/com.bansi.pagomovil E/MessageQueue-JNI: Exception in MessageQueue callback: handleReceiveCallback
04-04 16:20:41.220 16638-16638/com.bansi.pagomovil E/MessageQueue-JNI: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 24: TypedValue{t=0x3/d=0x8dd "res/drawable-xxhdpi-v4/list_divider_holo_light.9.png" a=1 r=0x108048d}
at android.content.res.TypedArray.getColor(TypedArray.java:447)
at it.sephiroth.android.library.tooltip.TooltipTextDrawable.
same thing happen on me
I tried to call:
Tooltip.make( getActivity(), new Tooltip.Builder() .anchor(getActivity().findViewById(R.id.help_button), Tooltip.Gravity.BOTTOM) .fitToScreen(true) .closePolicy(Tooltip.ClosePolicy.TOUCH_INSIDE_CONSUME, 10000) .text("BOTTOM. Touch outside to dismiss the tooltip") .withArrow(true) .maxWidth(300) .withStyleId(R.style.ToolTipLayoutDefaultStyle_Custom1) .build() ).show();
and get the error of
java.lang.UnsupportedOperationException: Failed to resolve attribute at index 6: TypedValue{t=0x1c/d=0xff33b5e5 a=1 r=0x1060012} at android.content.res.TypedArray.getColor(TypedArray.java:447)
Can you also reproduce this with the sample app? Because it's working correctly here.
The exception happened at the line of :
alpha = array.getColor(fadeOut, 0);
in the following code block:
public TooltipOverlayDrawable(Context context, int defStyleResId) {
this.mOuterPaint.setStyle(Style.FILL);
this.mInnerPaint.setStyle(Style.FILL);
TypedArray array = context.getTheme().obtainStyledAttributes(defStyleResId, styleable.TooltipOverlay);
for(int fadeIn = 0; fadeIn < array.getIndexCount(); ++fadeIn) {
int fadeOut = array.getIndex(fadeIn);
int alpha;
if(fadeOut == styleable.TooltipOverlay_android_color) {
alpha = array.getColor(fadeOut, 0);
this.mOuterPaint.setColor(alpha);
this.mInnerPaint.setColor(alpha);
Obviously, it is because that context.getTheme().obtainStyledAttributes does not include an attribute of color
So the solution could be: add following items into your theme:
<item name="colorAccent" tools:ignore="NewApi">#0092ff</item>
<item name="colorPrimary" tools:ignore="NewApi">#ffcc00</item>
<item name="colorPrimaryDark" tools:ignore="NewApi">#ff6600</item>
Frankly, the library could do something to avoid this issue without asking users to include above lines. :)
I have this issue as well...
Was this going to be resolved? I attempted to add the attributes wangbourne described, but it is not solving the issue. Unless I am doing it incorrectly?
I attempted to extend the default:
and add: withStyleId(R.style.MyTooltipStyle) to my builder