Reputation: 16193
I want to make the background darker when a PopupWindow
is shown. Just like Dolphin Browser does like-
Before the PopupWindow
After the PopupWindow
The background color is darker than what it was. So, how can we do this?
Upvotes: 6
Views: 13223
Reputation: 91
fun setBackgroundAlpha(activity: Activity, bgAlpha: Float) {
val lp: WindowManager.LayoutParams = activity.getWindow().getAttributes()
lp.alpha = bgAlpha
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND)
activity.getWindow().setAttributes(lp)
}
Upvotes: 0
Reputation: 359
In your xml file add something like this with width and height as 'match_parent'.
<RelativeLayout
android:id="@+id/bac_dim_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#C0000000"
android:visibility="gone" >
</RelativeLayout>
In your activity oncreate
//setting background dim when showing popup
back_dim_layout = (RelativeLayout) findViewById(R.id.bac_dim_layout);
Finally make visible when you show your popupwindow and make its visible gone when you exit popupwindow.
back_dim_layout.setVisibility(View.Visible);
back_dim_layout.setVisibility(View.GONE);
Upvotes: 5
Reputation: 104
try this code if your popup is an activity then it will help definetly. make a mystyle.xml file in values folder of your project and make these changes.
<resources>
<style name="customStyle" parent="@android:style/Theme.Dialog">
<item name="android:windowBackground">@android:color/transparent</item>
</style>
</resources>
do this change in menifest.xml
<activity android:name="yourActivity" android:theme="@style/customStyle"></activity>
Upvotes: 0
Reputation: 8079
If i am not wrong... you can create an activity with listview.... and put the theme as dialog in its manifest like this..
<activity android:theme="@android:style/Theme.Dialog" />
this will make the background darker..
Upvotes: 0