xml布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".Main3Activity"
>
<RelativeLayout
android:layout_weight="2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#FF8222">
<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/b"
android:layout_alignParentRight="true"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp" />
<ImageView
android:id="@+id/imageHead"
android:layout_width="80dp"
android:layout_height="80dp"
android:src="@drawable/c"
android:layout_below="@id/image"
android:layout_centerHorizontal="true" />
<LinearLayout
android:id="@+id/line1"
android:layout_below="@id/imageHead"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#FF9800">
<TextView
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="总资产"
android:textSize="25dp"
android:textColor="#fff"
android:gravity="center"
/>
<TextView
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="累计收费"
android:textSize="25dp"
android:textColor="#fff"
android:gravity="center"
/>
</LinearLayout>
<LinearLayout
android:layout_below="@id/line1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#FF9800">
<TextView
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="总资产"
android:textSize="25dp"
android:textColor="#fff"
android:gravity="center"
/>
<TextView
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="累计收费"
android:textSize="25dp"
android:textColor="#fff"
android:gravity="center"
/>
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_weight="3"
android:layout_width="match_parent"
android:layout_height="0dp">
</RelativeLayout>
<RelativeLayout
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp">
<Button
android:id="@+id/buttonOn"
android:layout_width="match_parent"
android:layout_height="80dp"
android:text="点一点"
android:textSize="30dp"
android:background="#FF5722"
android:textColor="#fff"
/>
</RelativeLayout>
</LinearLayout>
自定义Dialog
public class MyDialog extends Dialog {
private Button out;
private TextView title;
private TextView message;
private Button no;
private Button yes;
public MyDialog(Context context) {
super(context);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_item_dialog2);
initView();
}
private String mtitle;
public void setMtitle(String mtitle) {
this.mtitle = mtitle;
}
private String mMessage;
public void setmMessage(String mMessage) {
this.mMessage = mMessage;
}
private String okName;
public void setOkName(String okName) {
this.okName = okName;
}
private YesOnClick yesOnClick;
public interface YesOnClick{
void OnClick();
}
public void setYesOnClick(String name,YesOnClick yesOnClick) {
okName = name;
this.yesOnClick = yesOnClick;
}
private String noName;
public void setNoName(String noName) {
this.noName = noName;
}
private NoOnClick noOnClick;
public interface NoOnClick{
void OnClick();
}
public void setNoOnClick(String name,NoOnClick noOnClick) {
noName = name;
this.noOnClick = noOnClick;
}
private OutOnClick outOnClick;
public interface OutOnClick{
void Onclick();
}
public void setOutOnClick(OutOnClick outOnClick) {
this.outOnClick = outOnClick;
}
private void initView() {
out = (Button) findViewById(R.id.out);
out.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dismiss();
}
});
title = (TextView) findViewById(R.id.title);
title.setText(mtitle);
message = (TextView) findViewById(R.id.message);
message.setText(mMessage);
no = (Button) findViewById(R.id.no);
no.setText(noName);
no.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
noOnClick.OnClick();
dismiss();
}
});
yes = (Button) findViewById(R.id.yes);
yes.setText(okName);
yes.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
yesOnClick.OnClick();
dismiss();
}
});
}
}
MainActivity
public class Main3Activity extends AppCompatActivity implements View.OnClickListener {
private Button buttonOn;
private ImageView imageHead;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main3);
initView();
}
private void initView() {
buttonOn = (Button) findViewById(R.id.buttonOn);
buttonOn.setOnClickListener(this);
imageHead = (ImageView) findViewById(R.id.imageHead);
imageHead.setOnClickListener(this);
RequestOptions options = new RequestOptions();
options.circleCrop();
Glide.with(this).load(R.drawable.c).apply(options).into(imageHead);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.buttonOn:
MyDialog dialog = new MyDialog(this);
dialog.setMtitle("评价一下吧!");
dialog.setmMessage("满意吗?给个五星好评吧!我们会做的更好!");
dialog.setYesOnClick("五星好评", new MyDialog.YesOnClick() {
@Override
public void OnClick() {
Toast.makeText(Main3Activity.this, "谢谢您的好评,欢迎下次光临!", Toast.LENGTH_SHORT).show();
}
});
dialog.setNoOnClick("我要吐槽", new MyDialog.NoOnClick() {
@Override
public void OnClick() {
Toast.makeText(Main3Activity.this, "对您造成的损失还请谅解,我们一定会努力做到您满意!", Toast.LENGTH_SHORT).show();
}
});
dialog.setOutOnClick(new MyDialog.OutOnClick() {
@Override
public void Onclick() {
Toast.makeText(Main3Activity.this, "不要再逛逛了吗?", Toast.LENGTH_SHORT).show();
}
});
dialog.show();
break;
}
}
}