 {
super(context, themeResId);
this.mContext = context;
this.content = content;
this.listener = listener;
}
public CommomDialog setTitle(String title){
this.title = title;
return this;
}
public CommomDialog setPositiveButton(String name){
this.positiveName = name;
return this;
}
public CommomDialog setNegativeButton(String name){
this.negativeName = name;
return this;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dialog_commom_layout);
setCanceledOnTouchOutside(false);
initView();
}
private void initView() {
contentTxt = (TextView)findViewById(R.id.content);
titleTxt = (TextView)findViewById(R.id.title);
submitTxt = (TextView)findViewById(R.id.submit);
submitTxt.setOnClickListener(this);
cancelTxt = (TextView)findViewById(R.id.cancel);
cancelTxt.setOnClickListener(this);
contentTxt.setText(content);
if(!TextUtils.isEmpty(positiveName)){
submitTxt.setText(positiveName);
}
if(!TextUtils.isEmpty(negativeName)){
cancelTxt.setText(negativeName);
}
if(!TextUtils.isEmpty(title)){
titleTxt.setText(title);
}
}
@Override
public void onClick(View view) {
switch (view.getId()){
case R.id.cancel:
if(listener != null){
listener.onClick(this, false);
}
this.dismiss();
break;
case R.id.submit:
if(listener != null){
listener.onClick(this, true);
}
break;
}
}
public interface OnCloseListener{
void onClick(Dialog dialog, boolean confirm);
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:background="@color/colorWhite"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/title"
android:padding="12dp"
android:layout_marginTop="12dp"
android:text="提示"
android:textColor="#000"
android:textSize="16sp"
android:gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_gravity="center_horizontal"
android:lineSpacingExtra="3dp"
android:layout_marginLeft="40dp"
android:layout_marginTop="20dp"
android:layout_marginRight="40dp"
android:layout_marginBottom="30dp"
android:text="是否要删除门店"
android:textSize="12sp"
android:textColor="#000"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/dayinjiaguanlifont"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal">
<TextView
android:id="@+id/cancel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg_round_left_white"
android:layout_weight="1.0"
android:gravity="center"
android:text="否"
android:textSize="12sp"
android:textColor="#666"/>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="@color/cardview_shadow_end_color"/>
<TextView
android:id="@+id/submit"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg_round_right_white"
android:gravity="center"
android:layout_weight="1.0"
android:text="是"
android:textSize="12sp"
android:textColor="#666"/>
</LinearLayout>
</LinearLayout>
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
CommomDialog commomDialog = new CommomDialog(Test2Activity.this, R.style.dialog, "是否要删除门店", new CommomDialog.OnCloseListener() {
@Override
public void onClick(Dialog dialog, boolean confirm) {
Log.e(TAG, "onClick: "+confirm );
if (confirm){
Toast.makeText(getApplicationContext(),"删除",Toast.LENGTH_SHORT).show();
}else {
Toast.makeText(getApplicationContext(),"取消删除",Toast.LENGTH_SHORT).show();
}
dialog.dismiss();
}
});
commomDialog.setTitle("提示").show();
}
});
网友评论