Android中如何设置ProgressDialog的颜色和背景

2025-03-03 07:30:29
推荐回答(2个)
回答1:

  1. String.xml 文件,progressDialog是继承与Dialog,先设置一下progressDialog的风格,设置你想要的背景和颜色:        


     

           

        

    2.customprogressdialog.xml文件,定义自己的布局,由于我的需求只需要一个进度条以及一串显示的内容,所以布局比较接单



     

      android:layout_width="fill_parent" 

      android:layout_height="fill_parent" 

     android:orientation="horizontal"> 

        

            android:id="@+id/loadingImageView" 

            android:layout_width="wrap_content" 

           android:layout_height="wrap_content" 

          android:background="@anim/progress_round"/> 

        

           android:id="@+id/id_tv_loadingmsg" 

           android:layout_width="wrap_content" 

           android:layout_height="wrap_content" 

           android:layout_gravity="center_vertical" 

            android:textSize="20dp"/> 

    3.progress_round.xml文件.这个文件为了实现转动的效果,循环显示这些图片。


     

  android:oneshot="false"> 

     

     

    

     

     

     

     

     

4.CustomProgressDialog.java文件,这个是就是我们最终需要使用的progressDialog了。

public class CustomProgressDialog extends Dialog {

    private Context context = null;

    private static CustomProgressDialog customProgressDialog = null;

     

    public CustomProgressDialog(Context context){

        super(context);

        this.context = context;

    }

     

    public CustomProgressDialog(Context context, int theme) {

        super(context, theme);

    }

     

    public static CustomProgressDialog createDialog(Context context){

        customProgressDialog = new CustomProgressDialog(context,R.style.CustomProgressDialog);

        customProgressDialog.setContentView(R.layout.customprogressdialog);

        customProgressDialog.getWindow().getAttributes().gravity = Gravity.CENTER;

         

        return customProgressDialog;

    }

  

    public void onWindowFocusChanged(boolean hasFocus){

         

        if (customProgressDialog == null){

            return;

        }

         

        ImageView imageView = (ImageView) customProgressDialog.findViewById(R.id.loadingImageView);

        AnimationDrawable animationDrawable = (AnimationDrawable) imageView.getBackground();

        animationDrawable.start();

    }

 

   *

     * [Summary]

     *       setTitile 标题

     * @param strTitle

     * @return

     *

     */

    public CustomProgressDialog setTitile(String strTitle){

        return customProgressDialog;

    }

     

    /**

     *

     * [Summary]

     *       setMessage 提示内容

     * @param strMessage

     * @return

     *

     */

    public CustomProgressDialog setMessage(String strMessage){

        TextView tvMsg = (TextView)customProgressDialog.findViewById(R.id.id_tv_loadingmsg);

         

        if (tvMsg != null){

            tvMsg.setText(strMessage);

        }

         

        return customProgressDialog;

    }

}

回答2:

最简单的用setView()方法自定义的xml文件放进去.xml里想设置颜色背景什么都可以么