Home > Net >  Android: View Visibility set to View.VISIBLE but View is not Visible
Android: View Visibility set to View.VISIBLE but View is not Visible

Time:06-02

In my app (general construction described below), I have a custom dialog, built of a bunch of views and a blur-background view.
There are two ways to open that dialog:

  1. Clicking a button inside the app triggers the method that opens this dialog.
  2. A notification is shown when the dialog can be opened, and in the notification, there's a button that opens the app and is also supposed to open the dialog (By calling a BroadcastReceiver that lives in the same fragment as the dialog, and in the BroadcastReceiver I call the method that opens the dialog).

The first method works - clicking the button opens the dialog when it's supposed to.
The second, however, opens the app but not the dialog (To clarify - opening the dialog means changing its views visibility to View.VISIBLE).

To check what goes wrong, I used a Toast message that shows the visibility of the dialog every time the method that opens the dialog gets called. The Toast message shows "VISIBLE", so that means the Views visibility is set to View.VISIBLE indeed - but the dialog is not shown, nor the blur-background.

General Construction: The app has multiple Fragments, stored inside a view pager, inside the MainActivity and the dialog lives in the main fragment.

Might Be Relevant: when clicking the notifications button, the app opens, but the notification panel stays fully opened. The Toast message shows behind the notification panel.

dialog's XML: (stored inside of fragment_main.xml)

<com.google.android.material.circularreveal.CircularRevealFrameLayout
        android:id="@ id/dialog_container"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:visibility="invisible"
        app:layout_behavior="com.google.android.material.transformation.FabTransformationSheetBehavior">

    <com.google.android.material.card.MaterialCardView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:cardPreventCornerOverlap="true">

        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:padding="15.0dip">

            //Here is the content of the dialog, textviews and custom buttons

        </RelativeLayout>

    </com.google.android.material.card.MaterialCardView>

</com.google.android.material.circularreveal.CircularRevealFrameLayout>

dialog opening method:

private void openDialog() {
    //while "dialog" refers to the "dialog_container" in the dialog xml
    dialog.setVisibility(View.VISIBLE);
    fadeBlurIn(); //fades the blur-background view in
    dialog.setClickable(true);
}

calling the method in the BroadcastReceiver: (stored inside MainFragment.java)

private final BroadcastReceiver endTimerReceiver = new BroadcastReceiver() {
    @RequiresApi(api = Build.VERSION_CODES.M)
    @Override
    public void onReceive(Context context, Intent intent) {

            .
            .
            .

            boolean openDialog = {gets a boolean extra, works fine};
            if (openDialog){
                openDialog();
            }
        }

    }
};

this BroadcastReceiver is attached to this fragment and works fine.

Why doesn't the dialog show?
And how can I fix it?

CodePudding user response:

By notification panel, do you mean it's a bar on top of the app activity?

If so, my guess is that opening the notification panel pushes the dialog outside the device screen. Perhaps the dialog is constrained to the notification panel?

I'm not very sure about this, so sorry if this turns out to be incorrect!

Also, posting some code might help.

CodePudding user response:

You have made the view invisible and shown when clicked on either button or notification bar.

You can do is

Make the view visible and add the condition if called by Notification bar it remains as it is, if not then hide it and make it visible again on call on button.

  • Related