diff --git a/app/src/main/java/com/hss01248/dialogutildemo/MainActivity.java b/app/src/main/java/com/hss01248/dialogutildemo/MainActivity.java index 44a7f39..4dd1fe0 100644 --- a/app/src/main/java/com/hss01248/dialogutildemo/MainActivity.java +++ b/app/src/main/java/com/hss01248/dialogutildemo/MainActivity.java @@ -359,6 +359,7 @@ public void onThird() { "\n" + "创建 DevOps 工程 && 创建流水线\n" + "创建 DevOps 工程:企业空间—>DevOps 工程—>创建;填入工程名称,点击确定即可。"; + String msg3 = "one line test"; StyledDialog.buildIosAlert( "titlexxxxxxxxxxxxxxxxxxxxxtitlexxxxxxxxxxxxxxxxxxxxx", msg2, new MyDialogListener() { @Override public void onFirst() { @@ -386,6 +387,24 @@ public void onThird() { //.setBgRes(R.drawable.leak_canary_icon) //.setCustomContentHolder(new CustomContentHolder(this)) .show(); + StyledDialog.buildIosAlert( "titlexxxxxxxxxxxxxxxxxxxxxtitlexxxxxxxxxxxxxxxxxxxxx", msg3, new MyDialogListener() { + @Override + public void onFirst() { + showToast("onFirst"); + } + + @Override + public void onSecond() { + showToast("onSecond"); + } + + @Override + public void onThird() { + showToast("onThird"); + } + + + }).show(); break; case R.id.btn_ios_alert_vertical: StyledDialog.buildIosAlertVertical( "titlelll", msg, new MyDialogListener() { diff --git a/dialog/src/main/java/com/hss01248/dialog/StyledDialog.java b/dialog/src/main/java/com/hss01248/dialog/StyledDialog.java index 9ddce45..281c53b 100644 --- a/dialog/src/main/java/com/hss01248/dialog/StyledDialog.java +++ b/dialog/src/main/java/com/hss01248/dialog/StyledDialog.java @@ -189,7 +189,7 @@ public static ConfigBean buildMdMultiChoose(CharSequence title, CharSequence[] w public static ConfigBean buildIosAlert(CharSequence title, CharSequence msg, MyDialogListener listener) { - return DialogAssigner.getInstance().assignIosAlert(null, title, msg, listener); + return DialogAssigner.getInstance().assignIosAlert(null, title, msg, listener).setBtnText("ok"); } diff --git a/dialog/src/main/java/com/hss01248/dialog/config/ConfigBean.java b/dialog/src/main/java/com/hss01248/dialog/config/ConfigBean.java index db0fa5d..5b5a449 100644 --- a/dialog/src/main/java/com/hss01248/dialog/config/ConfigBean.java +++ b/dialog/src/main/java/com/hss01248/dialog/config/ConfigBean.java @@ -116,7 +116,7 @@ public ConfigBean setxResId(int xResId) { public CharSequence title; public CharSequence msg; public CharSequence text1 = DefaultConfig.btnTxt1; - public CharSequence text2 = DefaultConfig.btnTxt2; + public CharSequence text2 ; public CharSequence text3; public CharSequence hint1; diff --git a/dialog/src/main/java/com/hss01248/dialog/config/DefaultConfig.java b/dialog/src/main/java/com/hss01248/dialog/config/DefaultConfig.java index e914517..2265a92 100644 --- a/dialog/src/main/java/com/hss01248/dialog/config/DefaultConfig.java +++ b/dialog/src/main/java/com/hss01248/dialog/config/DefaultConfig.java @@ -89,7 +89,7 @@ public class DefaultConfig { public static void initBtnTxt(Context context){ btnTxt1 = context.getResources().getString(R.string.dialogutil_btn_sure); - btnTxt2 = context.getResources().getString(R.string.dialogutil_btn_cancel); + //btnTxt2 = context.getResources().getString(R.string.dialogutil_btn_cancel); bottomTxt = context.getResources().getString(R.string.dialogutil_btn_cancel); loadingTxt = context.getResources().getString(R.string.dialogutil_loading); uploadingTxt = context.getResources().getString(R.string.dialogutil_uploading); diff --git a/dialog/src/main/java/com/hss01248/dialog/ios/IosAlertDialogHolder.java b/dialog/src/main/java/com/hss01248/dialog/ios/IosAlertDialogHolder.java index d553633..a14a1f0 100644 --- a/dialog/src/main/java/com/hss01248/dialog/ios/IosAlertDialogHolder.java +++ b/dialog/src/main/java/com/hss01248/dialog/ios/IosAlertDialogHolder.java @@ -2,11 +2,14 @@ import android.content.Context; +import android.os.Build; import android.text.TextUtils; import android.text.method.HideReturnsTransformationMethod; import android.text.method.PasswordTransformationMethod; +import android.view.Gravity; import android.view.View; import android.view.ViewGroup; +import android.view.ViewTreeObserver; import android.widget.TextView; import android.widget.EditText; import android.widget.LinearLayout; @@ -215,6 +218,22 @@ private void setMsgStyleAndTxt(ConfigBean bean) { tvMsg.setTextColor(Tool.getColor(tvMsg.getContext(),bean.msgTxtColor)); tvMsg.setTextSize(bean.msgTxtSize); + + tvMsg.measure(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT); + tvMsg.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { + @Override + public void onGlobalLayout() { + int lineCount = tvMsg.getLineCount(); + if(lineCount>0){ + tvMsg.getViewTreeObserver().removeOnGlobalLayoutListener(this); + if (lineCount ==1){ + tvMsg.setGravity(Gravity.CENTER); + }else { + tvMsg.setGravity(Gravity.LEFT); + } + } + } + }); } }