skydoves / Balloon

:balloon: Modernized and sophisticated tooltips, fully customizable with an arrow and animations for Android.
https://skydoves.github.io/libraries/balloon/html/balloon/com.skydoves.balloon/index.html
Apache License 2.0
3.69k stars 289 forks source link

Not working on API 16 #23

Closed luizfp closed 4 years ago

luizfp commented 4 years ago

Please complete the following information:

Describe the Bug:

We are using this library to show a tooltip inside a dialog fragment but with crashs with a NPE when we try to show the balloon:

java.lang.NullPointerException
        at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:465)
        at android.view.View.measure(View.java:15172)
        at com.skydoves.balloon.Balloon$showAlignTop$$inlined$show$1.run(Balloon.kt:267)
        at android.os.Handler.handleCallback(Handler.java:615)
        at android.os.Handler.dispatchMessage(Handler.java:92)
        at android.os.Looper.loop(Looper.java:137)
        at android.app.ActivityThread.main(ActivityThread.java:4745)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:511)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
        at dalvik.system.NativeStart.main(Native Method)

Code we use to build the Balloon:

@NonNull
    private Balloon buildBalloon(@NonNull final Context context) {
        final Balloon balloon = new Balloon.Builder(context)
                .setLayout(R.layout.partial_custom_field_tooltip)
                .setArrowSize(10)
                .setArrowOrientation(ArrowOrientation.BOTTOM)
                .setArrowVisible(true)
                .setSpace(20)
                .setPadding(8)
                .setCornerRadius(4f)
                .setTextColor(Color.WHITE)
                .setBackgroundColor(Colors.getColor(R.color.custom_fields_tooltip_background))
                .setBalloonAnimation(BalloonAnimation.FADE)
                .setDismissWhenClicked(true)
                .setOnBalloonOutsideTouchListener(this)
                .build();
        ((TextView) balloon.getContentView().findViewById(R.id.txt_customFieldTooltip))
                .setText("Text");
        return balloon;
    }

Custom layout:

<TextView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/txt_customFieldTooltip"
    android:layout_width="300dp"
    android:layout_height="wrap_content"
    android:textColor="@color/white"
    android:gravity="center"
    android:textSize="@dimen/font_normal"
    tools:background="@color/custom_fields_tooltip_background"
    tools:text="@tools:sample/lorem/random" />

And to show: mBalloon.showAlignTop(view);

We also test on API 26 and it works fine.

skydoves commented 4 years ago

Hi, @luizfp thank you for your issue :) But unfortunately, the minimum API level is changed 16 to 17 in the latest release because of the bug of the Android SDK when inflating and measuring RelativeLayout in API level 16. You can check out the details here. Thank you!