android - Translucent dialog with margin -
i need create translucent dialog, 100dp margin top.
in code, add this:
dialog dialog = new dialog(getactivity(), android.r.style.theme_translucent_notitlebar); dialog.setcontentview(r.layout.transparent_progress_bar);
and transparent_progress_bar
:
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="match_parent" android:layout_width="match_parent" android:layout_margintop="100dp" > <progressbar android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerinparent="true" android:layout_gravity="center" android:background="@android:color/transparent" android:indeterminate="true" android:indeterminatedrawable="@drawable/rotate_progress_bar" android:indeterminateonly="true" android:padding="@dimen/android_spacing_double"/> </relativelayout>
but doesn't work.
idea on how can modify theme or add margin this?
try this!!
in transparent_progress_bar.xml
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/relative_dialog_control" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/transparent" android:layout_margintop="8dp" > <view android:id="@+id/view_close_top" android:layout_width="match_parent" android:layout_height="100dp" /> <relativelayout android:id="@+id/relative_popup" android:layout_width="match_parent" android:layout_height="207dp" android:layout_below="@+id/view_close_top" android:layout_marginleft="9dp" android:layout_marginright="9dp" android:background="#ffffff" android:padding="0dp"> <progressbar android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerinparent="true" android:layout_gravity="center" android:background="@android:color/transparent" android:indeterminate="true" android:indeterminatedrawable="@drawable/rotate_progress_bar" android:indeterminateonly="true" android:padding="@dimen/android_spacing_double"/> </relativelayout> <view android:id="@+id/view_close" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_below="@+id/relative_popup" /> </relativelayout>
in res/value/style.xml add
<style name="theme.transparent" parent="theme.appcompat.light.dialog"> <item name="android:windowistranslucent">false</item> <item name="android:windowbackground">@android:color/transparent</item> <item name="windownotitle">true</item> </style>
this code when show dialog
private void showpopupcontrol() { final appcompatdialog dialog = new appcompatdialog(mainactivity.this, r.style.theme_transparent); //dialog.getwindow().clearflags(windowmanager.layoutparams.flag_dim_behind); dialog.setcontentview(r.layout.transparent_progress_bar); viewgroup.layoutparams params = dialog.getwindow().getattributes(); params.width = viewgroup.layoutparams.match_parent; dialog.getwindow().setattributes((android.view.windowmanager.layoutparams) params); dialog.findviewbyid(r.id.relative_dialog_control).setvisibility(view.visible); dialog.findviewbyid(r.id.view_close).setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { dialog.dismiss(); } }); dialog.findviewbyid(r.id.view_close_top).setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { dialog.dismiss(); } }); dialog.show(); }
happycoding;
Comments
Post a Comment