我们自己的android中的进度对话框

时间:2011-10-08 13:07:03

标签: android android-layout

如何在android中创建蓝色背景和我自己的微调器样式的进度对话框?请帮帮我。

1 个答案:

答案 0 :(得分:2)

            Dialog  dialog = new Dialog(MainActivity.this, R.style.mydialogstyle);
            dialog.setContentView(R.layout.dialogmain);
            dialog.setCancelable(false);

            ProgressBar pbar = (ProgressBar) dialog.findViewById(R.id.progressBar);

            Button btncancel = (Button) dialog.findViewById(R.id.cancelbtn);
            btncancel.setOnClickListener(new OnClickListener() {

                public void onClick(View v) {
                    dialog.dismiss();
                }
            });

            dialog.show();

R.layout.dialogmain --->>

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:background="#0000FF" android:layout_height="wrap_content">
     <ProgressBar style="?android:attr/progressBarStyleHorizontal"
        android:progressDrawable="@android:drawable/progress_horizontal"//You can change drawable of spinner 
        android:layout_marginTop="10dip" android:layout_width="250dip"
        android:id="@+id/progressBar" android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"></ProgressBar>
    <Button android:layout_width="wrap_content" android:background="@drawable/cancel"
        android:layout_height="wrap_content" android:text=""         android:id="@+id/cancelbtn"
        android:layout_marginTop="2dip" android:layout_below="@+id/progressBar"
        android:layout_centerHorizontal="true"></Button>

</RelativeLayout>

RES-&GT;值 - &GT; style.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="mydialogstyle" parent="android:style/Theme.Dialog">
        <item name="android:windowBackground">@null</item>
        <item name="android:windowNoTitle">false</item>
    </style>
</resources>