How to create custom progressDialog

会有一股神秘感。 提交于 2019-12-06 15:30:30
Sohail Zahid

Create custom dialog with progress bar in it for making it consistent for different devices.

final Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.custom);
dialog.setTitle("Title...");

// set the custom dialog components - title, ProgressBar and button
TextView text = (TextView) dialog.findViewById(R.id.text);
text.setText("COUSTOM PROGRESS TITLE");
ProgressBar prog = (ProgressBar) dialog.findViewById(R.id.myprogress);
prog.setVisibilty(VISIBLE);

Button dialogButton = (Button) dialog.findViewById(R.id.dialogButtonOK);
   // if button is clicked, close the custom dialog
   dialogButton.setOnClickListener(new OnClickListener() {
     @Override
     public void onClick(View v) {
        dialog.dismiss();
     }
});

dialog.show();

layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <ProgressBar
        android:id="@+id/myprogress"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@color/colorPrimary"
        android:layout_marginRight="5dp" />

    <TextView
        android:id="@+id/text"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textColor="#FFF"
        android:layout_toRightOf="@+id/image"/>/>

     <Button
        android:id="@+id/dialogButtonOK"
        android:layout_width="100px"
        android:layout_height="wrap_content"
        android:text=" Ok "
        android:layout_marginTop="5dp"
        android:layout_marginRight="5dp"
        android:layout_below="@+id/myprogress"
        />

</RelativeLayout>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!