android - how to set background image for progress dialog? -
i'm new android..
in app i'm using progress dialog. want set background image progress dialog. how implement this?
protected void onpreexecute() { super.onpreexecute(); pdialog = new progressdialog(frontactivity.this); pdialog.setmessage("loading grades. please wait..."); pdialog.setindeterminate(false); pdialog.setcancelable(false); pdialog.show(); }
this layout custom progress dialog :
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/linearlayout" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_gravity="center" android:background="@layout/custom_rounded_box" android:orientation="vertical" > <linearlayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight=".6" android:orientation="horizontal" > <progressbar android:id="@+id/progress" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical|center_horizontal" android:indeterminatedrawable="@drawable/progress_background" /> <textview android:id="@+id/dialogtitle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight=".3" android:gravity="center_horizontal|center_vertical" android:text="" android:textsize="22sp" android:textstyle="bold" /> <progressbar android:id="@+id/progress" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_weight=".05" android:background="@android:color/black" android:indeterminatedrawable="@drawable/progress_background" android:visibility="invisible" /> </linearlayout> <linearlayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="0.5" android:orientation="vertical" > <imageview android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/light_gray_line" > </imageview> <textview android:id="@+id/dialogmessage" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_below="@+id/dialogtitle" android:focusable="true" android:focusableintouchmode="true" android:gravity="center_vertical" android:maxlines="10" android:padding="10dip" android:scrollbars="vertical" android:text="" android:textsize="18sp" > </textview> </linearlayout> <relativelayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:layout_weight=".6" > <linearlayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerinparent="true" android:orientation="horizontal" > <button android:id="@+id/okbutton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/dialogmessage" android:layout_centerhorizontal="true" android:layout_marginleft="10dip" android:layout_marginright="10dp" android:background="@drawable/ok_btn" > </button> <button android:id="@+id/cancelbutton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/dialogmessage" android:layout_centerhorizontal="true" android:layout_marginleft="10dp" android:layout_marginright="10dip" android:background="@drawable/cancel_btn" /> </linearlayout> </relativelayout> </linearlayout>`
and custom dialog class
public class customizedialog extends dialog implements onclicklistener { button okbutton; context mcontext; textview mtitle = null; textview mmessage = null; view v = null; button cancelbutton; progressbar progressbar; public customizedialog(context context) { super(context); mcontext = context; /** 'window.feature_no_title' - used hide mtitle */ requestwindowfeature(window.feature_no_title); /** design dialog in main.xml file */ setcontentview(r.layout.custom_dialog_box); v = getwindow().getdecorview(); v.setbackgroundresource(android.r.color.transparent); mtitle = (textview) findviewbyid(r.id.dialogtitle); mmessage = (textview) findviewbyid(r.id.dialogmessage); okbutton = (button) findviewbyid(r.id.okbutton); cancelbutton = (button) findviewbyid(r.id.cancelbutton); cancelbutton.setonclicklistener(this); okbutton.setonclicklistener(this); progressbar = (progressbar) findviewbyid(r.id.progress); } @override public void settitle(charsequence title) { super.settitle(title); mtitle.settext(title); } @override public void settitle(int titleid) { super.settitle(titleid); mtitle.settext(mcontext.getresources().getstring(titleid)); } /** * set message text dialog's window. * * @param message * - new message display in title. */ public void setmessage(charsequence message) { mmessage.settext(message); mmessage.setmovementmethod(scrollingmovementmethod.getinstance()); } /** * set message id * * @param messageid */ public void setmessage(int messageid) { mmessage.settext(mcontext.getresources().getstring(messageid)); mmessage.setmovementmethod(scrollingmovementmethod.getinstance()); } @override public void onclick(view v) { // todo auto-generated method stub }
}
you can utilize in activity passing title , message
mcustomizedialog = new customizedialog(myactivity.this); mcustomizedialog.settitle("title"); mcustomizedialog.setmessage("message"); mcustomizedialog.okbutton.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { mcustomizedialog.dismiss(); }); mcustomizedialog.show();
hope helps :)
android background progressdialog
No comments:
Post a Comment