AlertDialog 사용자 정의 레이아웃
activity 호출
private void showAlertDialog() {
final AlertDialogUtil dialog = new AlertDialogUtil(this, false, null); // false " " ,true
dialog.setMessage(" ");
dialog.setBtnPositiveValue(" ");
dialog.setPositiveClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
dialog.dismiss();
}
});
dialog.setBtnNegativeValue(" ");
dialog.setNegativeClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
dialog.show();
} AlertDialogUtil 도구 클래스
public class AlertDialogUtil extends AlertDialog {
private Button btnPositive, btnNegative;
private TextView tvMessage;
private String message;
private String btnPositiveValue, btnNegativeValue;
private View.OnClickListener positiveListener, negativeListener;
public AlertDialogUtil(Context context, boolean cancelable,
OnCancelListener cancelListener) {
super(context, cancelable, cancelListener);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dialog_confirm);
initView();
}
public void setMessage(String message) {
this.message = message;
}
public void setBtnPositiveValue(String val) {
this.btnPositiveValue = val;
}
public void setPositiveClickListener(View.OnClickListener listener) {
this.positiveListener = listener;
}
public void setBtnNegativeValue(String val) {
this.btnNegativeValue = val;
}
public void setNegativeClickListener(View.OnClickListener listener) {
this.negativeListener = listener;
}
private void initView() { //
btnPositive = (Button) findViewById(R.id.btn_alertDialogutil_cancel);
btnNegative = (Button) findViewById(R.id.btn_alertDialogutil_confirm);
tvMessage = (TextView) findViewById(R.id.textView_title_mydialog);
if (isNullEmptyBlank(message)) {
tvMessage.setVisibility(View.GONE);
} else {
this.setCancelable(cancelable);
tvMessage.setText(message);
}
if (!(isNullEmptyBlank(btnPositiveValue))) {
btnPositive.setText(btnPositiveValue);
this.btnPositive.setOnClickListener(positiveListener);
}
if (!(isNullEmptyBlank(btnNegativeValue))) {
btnNegative.setText(btnNegativeValue);
this.btnNegative.setOnClickListener(negativeListener);
}
}
private static boolean isNullEmptyBlank(String str) {
if (str == null || "".equals(str) || "".equals(str.trim()))
return true;
return false;
}
} xml 레이아웃
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="260dp"
android:layout_height="130dp"
android:layout_gravity="center"
android:background="@drawable/feedback_edite_bg"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center" >
<TextView
android:id="@+id/textView_title_mydialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/color_black"
android:textSize="21sp" >
</TextView>
</LinearLayout>
<LinearLayout
android:id="@+id/ll_alertDialogutil"
android:layout_width="match_parent"
android:layout_height="51dp"
android:orientation="vertical"
android:visibility="gone" >
<ImageView
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/color_linear" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:orientation="horizontal" >
<Button
android:id="@+id/btn_alertDialogutil_cancel"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@color/color_transparent"
android:textColor="@color/color_blue"
android:textSize="15sp"
android:visibility="gone" />
<ImageView
android:id="@+id/iv_alertDialogutil"
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="@color/color_linear"
android:visibility="gone" />
<Button
android:id="@+id/btn_alertDialogutil_confirm"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@color/color_transparent"
android:textColor="@color/color_blue"
android:textSize="15sp"
android:visibility="gone" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Kotlin의 기초 - 2부지난 글에서는 Kotlin이 무엇인지, Kotlin의 특징, Kotlin에서 변수 및 데이터 유형을 선언하는 방법과 같은 Kotlin의 기본 개념에 대해 배웠습니다. 유형 변환은 데이터 변수의 한 유형을 다른 데이터...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.