Search code examples
androidviewfadeinfloating-action-button

Android View initialize and display problems


I try to display a "custom" view when FloatingButton is pressed, but something gone wrong with the view (like Google Agenda when you tap on the FloatingButton, such as a "fade in" view).

This is my view (it is located between the a ViewPager and the Fab buttons):

<View
    android:id="@+id/shadowView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#F2FFFFFF"
    android:visibility="gone" />

This is the method:

public void animateFAB() {

    if (isFabOpen) {

        //animation classic 1
        fabNormal.startAnimation(rotate_backward);
        fabShare.startAnimation(fab_close);
        fabFavorit.startAnimation(fab_close);
        fabShare.setClickable(false);
        fabFavorit.setClickable(false);
        isFabOpen = false;
        mShadowView.setVisibility(View.VISIBLE);


    } else {
        //animation classic 1
        fabNormal.startAnimation(rotate_forward);
        fabShare.startAnimation(fab_open);
        fabFavorit.startAnimation(fab_open);
        fabShare.setClickable(true);
        fabFavorit.setClickable(true);
        isFabOpen = true;
        mShadowView.setVisibility(View.GONE);
    }
}

And this is the problem:

java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.setVisibility(int)' on a null object reference

Well I didn't find any solution of this problem, someone can help me?

thanks


Solution

  • Ok, this is the solution:

    mShadowView = findViewById(R.id.shadowView);
    
    fabShare.setOnClickListener(this);
    fabFavorit.setOnClickListener(this);
    

    I just put the declaration of the View before the setOnClickListener