Skip to content

Commit

Permalink
完善ios样式dialog的显示
Browse files Browse the repository at this point in the history
  • Loading branch information
hss01248 committed Jan 9, 2023
1 parent c818e6c commit 2ac948e
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 3 deletions.
19 changes: 19 additions & 0 deletions app/src/main/java/com/hss01248/dialogutildemo/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion dialog/src/main/java/com/hss01248/dialog/StyledDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
}
});
}
}

Expand Down

0 comments on commit 2ac948e

Please sign in to comment.