diff --git a/app/src/main/java/com/android/tu/mloadingdialog/MainActivity.java b/app/src/main/java/com/android/tu/mloadingdialog/MainActivity.java index fb2257e..20e909f 100644 --- a/app/src/main/java/com/android/tu/mloadingdialog/MainActivity.java +++ b/app/src/main/java/com/android/tu/mloadingdialog/MainActivity.java @@ -7,7 +7,7 @@ import android.view.View; import android.widget.Button; -import com.android.tu.loadingdialog.LoadingDailog; +import com.android.tu.loadingdialog.LoadingDialog; public class MainActivity extends AppCompatActivity implements View.OnClickListener{ @@ -27,10 +27,10 @@ protected void onCreate(Bundle savedInstanceState) { public void onClick(View view) { switch (view.getId()){ case R.id.style1_btn: - LoadingDailog.Builder builder1=new LoadingDailog.Builder(MainActivity.this) + LoadingDialog.Builder builder1=new LoadingDialog.Builder(MainActivity.this) .setMessage("加载中...") .setCancelable(false); - final LoadingDailog dialog1=builder1.create(); + final LoadingDialog dialog1=builder1.create(); dialog1.show(); handler.postDelayed(new Runnable() { @Override @@ -40,10 +40,10 @@ public void run() { },2000); break; case R.id.style2_btn: - LoadingDailog.Builder builder2=new LoadingDailog.Builder(MainActivity.this) + LoadingDialog.Builder builder2=new LoadingDialog.Builder(MainActivity.this) .setShowMessage(false) .setCancelable(false); - final LoadingDailog dialog2=builder2.create(); + final LoadingDialog dialog2=builder2.create(); dialog2.show(); handler.postDelayed(new Runnable() { @Override diff --git a/loadingdialog/src/main/java/com/android/tu/loadingdialog/LoadingDialog.java b/loadingdialog/src/main/java/com/android/tu/loadingdialog/LoadingDialog.java new file mode 100644 index 0000000..0b63db6 --- /dev/null +++ b/loadingdialog/src/main/java/com/android/tu/loadingdialog/LoadingDialog.java @@ -0,0 +1,98 @@ +package com.android.tu.loadingdialog; + +import android.app.Dialog; +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.TextView; + +/** + * Created by tjy on 2017/6/19. + */ +public class LoadingDialog extends Dialog{ + + + public LoadingDialog(Context context) { + super(context); + } + + public LoadingDialog(Context context, int themeResId) { + super(context, themeResId); + } + + public static class Builder{ + + private Context context; + private String message; + private boolean isShowMessage=true; + private boolean isCancelable=false; + private boolean isCancelOutside=false; + + + public Builder(Context context) { + this.context = context; + } + + /** + * 设置提示信息 + * @param message + * @return + */ + + public Builder setMessage(String message){ + this.message=message; + return this; + } + + /** + * 设置是否显示提示信息 + * @param isShowMessage + * @return + */ + public Builder setShowMessage(boolean isShowMessage){ + this.isShowMessage=isShowMessage; + return this; + } + + /** + * 设置是否可以按返回键取消 + * @param isCancelable + * @return + */ + + public Builder setCancelable(boolean isCancelable){ + this.isCancelable=isCancelable; + return this; + } + + /** + * 设置是否可以取消 + * @param isCancelOutside + * @return + */ + public Builder setCancelOutside(boolean isCancelOutside){ + this.isCancelOutside=isCancelOutside; + return this; + } + + public LoadingDialog create(){ + + LayoutInflater inflater = LayoutInflater.from(context); + View view=inflater.inflate(R.layout.dialog_loading,null); + LoadingDialog loadingDailog=new LoadingDialog(context,R.style.MyDialogStyle); + TextView msgText= (TextView) view.findViewById(R.id.tipTextView); + if(isShowMessage){ + msgText.setText(message); + }else{ + msgText.setVisibility(View.GONE); + } + loadingDailog.setContentView(view); + loadingDailog.setCancelable(isCancelable); + loadingDailog.setCanceledOnTouchOutside(isCancelOutside); + return loadingDailog; + + } + + + } +}