如何设置自定义布局以进入对话框背景?

时间:2016-04-06 10:35:26

标签: android layout progressdialog

标题中的问题)请帮帮我 我想从中做出这个 enter image description here

enter image description here

我尝试过实施它。

mProgressDialog = new ProgressDialog(this);
mProgressDialog.getWindow().setContentView(R.layout.footcloth);
mProgressDialog.setMessage(Constants.PROGRESS_DIALOG_MESSAGE);
mProgressDialog.show();

但是此代码抛出异常

java.lang.RuntimeException: Unable to start activity ComponentInfo{im.anticafe.anticafeim/im.anticafe.anticafeim.activities.HomeActivity}: android.util.AndroidRuntimeException: requestFeature() must be called before adding content

此代码在活动BottomBarActivity

中实现
abstract public class BottomBarActivity extends AppCompatActivity implements View.OnClickListener {

    private static final String TAG = "bottomBarActivity";
    private int mWidth;
    private ProgressDialog mProgressDialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        ...
        mProgressDialog = new ProgressDialog(this);
        mProgressDialog.getWindow().setContentView(R.layout.footcloth);
        mProgressDialog.setMessage(Constants.PROGRESS_DIALOG_MESSAGE);
        mProgressDialog.show();
        ...
    }

    ...
}

此活动在其他活动中得到扩展。 所以,请帮我解决我的问题,请) 感谢)

1 个答案:

答案 0 :(得分:5)

有2个答案

  1. 如果您想在“进度”对话框中更改背景的颜色(透明度),我建议您使用片段并切换它们。在片段中,您可以设置任何属性并放入ProgressBar
  2. 完成重新加载后,您可以再次切换回或另一个片段

    1. 如果您想更改进度对话框

      public class TransparentProgressDialog extends Dialog {
      
        public TransparentProgressDialog(Context context) {
          super(context, R.style.TransparentProgressDialog);
      
          WindowManager.LayoutParams wlmp = getWindow().getAttributes();
      
          wlmp.gravity = Gravity.CENTER_HORIZONTAL;
          getWindow().setAttributes(wlmp);
          setTitle(null);
          setCancelable(false);
          setOnCancelListener(null);
          View view = LayoutInflater.from(context).inflate(
                  R.layout.progress_dialog, null);
          setContentView(view);
         }
      }
      
    2. 在您的活动中使用

      TransparentProgressDialog pd = new TransparentProgressDialog(context);
      pd.show();
      
      ....
      
      if (pd.isShowing()){
                  pd.dismiss();
              }