0

I found this most excellent solution to the exact issue I am trying to solve here:

Blur or dim background when Android PopupWindow active

However, I cannot get the parent view to dim by setting the Alpha. I am using a rectangle shape as the solution suggests The Drawable is a GradientDrawable. Here's the code I'm using:

                @Override
                public void onViewPhoto(PostObject item) {
                    rootView.getForeground().setAlpha(220);
                    rootView.invalidate();
                    PhotoPopup pp = new PhotoPopup(getActivity(), rootView, item.getObject_Id());
                    pp.show();
                    rootView.getForeground().setAlpha(0);
                    rootView.invalidate();
                }

The code above is in the parent fragment that will host the popup. It's called via a custom callback. The call is made by an ArrayAdapter derived adapter when the user clicks on a photo in the listview item.

I've tried this on both KitKat (Asus Memo Pad) and JellyBean (Samsung Galaxy Tab 2) Any ideas?

For completeness: Here's the Layout

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/streamList_rootFrame"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:foreground="@drawable/shape_dim_window" >

    <ListView
        android:id="@+id/streamList_listview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    </ListView>

</FrameLayout>

And the shape itself:

<shape
     xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >
    <solid android:color="#000000" />
</shape>
Community
  • 1
  • 1
psparago
  • 1,113
  • 11
  • 21

1 Answers1

0

You can use DIALOG by using android:theme="@android:style/Theme.Dialog" to do that. Create an activity and in your AndroidManifest.xml define the activity as:

<activity android:name=".activity.YourActivity"
android:label="@string/your_activity_label"
android:theme="@android:style/Theme.Dialog">

It will create a popup and your background would be dim.

Maveňツ
  • 1
  • 12
  • 50
  • 89
  • Thank you very much for the very quick response. This may be something I have to look into, however, I've got a lot of code invested in the solution I'm using and I'd love to know why what I'm doing isn't working. I'm hoping for a simple fix if possible. – psparago Oct 06 '14 at 13:31
  • I agree with this answer... wrapping a `ListView` in a `FrameLayout` is not only more complicated, but it will end up being more inefficient (the GPU will need to draw twice as many pixels... once for the foreground frame layout and again for the list view). If you use a translucent activity dialog, the GPU will be able to optimize this background fading effect. – Alex Lockwood Oct 06 '14 at 15:46
  • I guess some context is missing. I've gone down the dialog route and for what I'm trying to do, it doesn't work well. I chose the popup window because it seems to be better regarding moving, flinging etc as well as playing video while moving. This is a special needs oriented application so, smooth motion is essential. I couldn't get the same motion and gesture performance from a dialog. – psparago Oct 06 '14 at 19:20