selfDialog = new MyDialog(mContext);
selfDialog.setTitle("自定义话题");
selfDialog.setMessage1("话题名称");
selfDialog.setMessage2("话题简介");
//final String editStr1 = selfDialog.getEditStr1();
//String editStr2 = selfDialog.getEditStr2();
selfDialog.setYesOnclickListener("确定", new MyDialog.onYesOnclickListener() {
@Override
public void onYesClick() {
final String editStr1 = selfDialog.messageTv1.getText().toString();
String editStr2 = selfDialog.messageTv2.getText().toString();
Toast.makeText(mContext, "点击了--确定--按钮", Toast.LENGTH_LONG).show();
selfDialog.dismiss();
Intent data = new Intent();
data.putExtra("SelfHuaTieName",editStr1 );
LogUtils.e(TAG, "SelfHuaTieName " + editStr1);
setResult(10112, data);
finish();
}
});
selfDialog.setNoOnclickListener("取消", new MyDialog.onNoOnclickListener() {
@Override
public void onNoClick() {
Toast.makeText(mContext, "点击了--取消--按钮", Toast.LENGTH_LONG).show();
selfDialog.dismiss();
}
});
selfDialog.show();
/**
- Created by JsonQiu on 2017/8/29 16:08.
*/
public class MyDialog extends Dialog {
private Button yes;
private Button no;
private TextView titleTv;
public EditText messageTv1;
public EditText messageTv2;
private String titleStr;
private String messageStr1;
private String messageStr2;
private String yesStr, noStr;
private onNoOnclickListener noOnclickListener;
private onYesOnclickListener yesOnclickListener;
public void setNoOnclickListener(String str, onNoOnclickListener onNoOnclickListener) {
if (str != null) {
noStr = str;
}
this.noOnclickListener = onNoOnclickListener;
}
public void setYesOnclickListener(String str, onYesOnclickListener onYesOnclickListener) {
if (str != null) {
yesStr = str;
}
this.yesOnclickListener = onYesOnclickListener;
}
public MyDialog(Context context) {
super(context, R.style.MyDialog);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.my_dialog);
setCanceledOnTouchOutside(false);
initView();
initData();
initEvent();
}
private void initEvent() {
yes.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (yesOnclickListener != null) {
yesOnclickListener.onYesClick();
}
}
});
no.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (noOnclickListener != null) {
noOnclickListener.onNoClick();
}
}
});
}
private void initData() {
if (titleStr != null) {
titleTv.setText(titleStr);
}
if (messageStr1 != null) {
messageTv1.setHint(messageStr1);
}
if (messageStr2 != null) {
messageTv2.setHint(messageStr2);
}
if (yesStr != null) {
yes.setText(yesStr);
}
if (noStr != null) {
no.setText(noStr);
}
}
private void initView() {
yes = (Button) findViewById(R.id.mydialog_ye);
no = (Button) findViewById(R.id.mydialog_no);
titleTv = (TextView) findViewById(R.id.mydialog_title);
messageTv1 = (EditText) findViewById(R.id.mydialog_et1);
messageTv2 = (EditText) findViewById(R.id.mydialog_et2);
}
public void setTitle(String title) {
titleStr = title;
}
public void setMessage1(String message) {
messageStr1 = message;
}
public void setMessage2(String message) {
messageStr2 = message;
}
public String getEditStr(EditText etView) {
return etView.getText().toString();
}
public String getEditStr1( ) {
return messageTv1.getText().toString();
}
public String getEditStr2( ) {
return messageTv2.getText().toString();
}
public interface onYesOnclickListener {
public void onYesClick();
}
public interface onNoOnclickListener {
public void onNoClick();
}
}
<style name="MyDialog" parent="android:style/Theme.Dialog">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
</style>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@drawable/bg_yjjx_gary"
android:orientation="vertical">
<TextView
android:id="@+id/mydialog_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="15dp"
android:background="@drawable/edittext_edit_shape"
android:gravity="center"
android:padding="8dp"
android:text="自定义话题"
android:textColor="@color/word"
android:textColorHint="@color/word"
android:textSize="@dimen/text_large_size" />
<EditText
android:id="@+id/mydialog_et1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:background="@drawable/edittext_edit_shape"
android:gravity="left"
android:hint="话题名称"
android:padding="8dp"
android:textColor="@color/word"
android:textSize="@dimen/text_small_size_14" />
<EditText
android:id="@+id/mydialog_et2"
android:layout_width="match_parent"
android:layout_height="@dimen/hight86"
android:layout_margin="15dp"
android:layout_marginTop="10dp"
android:background="@drawable/edittext_edit_shape"
android:gravity="left"
android:hint="话题简介"
android:padding="8dp"
android:textColor="@color/word"
android:textSize="@dimen/text_small_size_14" />
<ImageView
android:layout_width="match_parent"
android:layout_height="1px"
android:layout_marginTop="15dp"
android:background="@color/fenge" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:background="@drawable/edittext_edit_shape"
android:orientation="horizontal">
<Button
android:id="@+id/mydialog_no"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_weight="1"
android:background="@null"
android:gravity="center"
android:padding="10dp"
android:singleLine="true"
android:text="取消"
android:textColor="#7D7D7D"
android:textSize="16sp" />
<View
android:layout_width="0.5px"
android:layout_height="match_parent"
android:background="@color/fenge" />
<Button
android:id="@+id/mydialog_ye"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_weight="1"
android:background="@null"
android:gravity="center"
android:padding="10dp"
android:singleLine="true"
android:text="创建"
android:textColor="#38ADFF"
android:textSize="16sp" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>