23、微信-温馨提示对话框WarnTipDialog

这个类重用性蛮好的,以后可以直接借鉴使用。

布局:
xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="top"
android:gravity="top"
android:paddingLeft="10dip"
android:paddingRight="10dip" >

<LinearLayout
android:id="@+id/dialog_generic_layout_root"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="60dip"
android:background="@drawable/btn_bg_gray"
android:clickable="true"
android:focusable="true"
android:orientation="vertical" >

<LinearLayout
android:id="@+id/dialog_generic_layout_top"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:orientation="vertical" >

<LinearLayout
android:id="@+id/dialog_generic_layout_content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dip" >

<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fadingEdge="none" >

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:paddingBottom="15dip"
android:paddingTop="15dip" >

<TextView
android:id="@+id/dialog_generic_htv_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="您确定要举报该好友吗?"
android:textColor="@color/black"
android:textSize="16sp" />
LinearLayout>
ScrollView>
LinearLayout>
LinearLayout>

<View
android:layout_width="fill_parent"
android:layout_height="1dip"
android:background="#E3E0D5" />

<LinearLayout
android:id="@+id/dialog_generic_layout_bottom"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
android:paddingBottom="5dp"
android:paddingLeft="6dip"
android:paddingRight="6dip" >

<TextView
android:id="@+id/btn_cancel"
style="@style/txt_titleStyle1"
android:layout_width="0.0dip"
android:layout_height="40dp"
android:layout_weight="1.0"
android:gravity="center"
android:text="取消"
android:textColor="@color/black1"
android:textSize="16sp" />

<View
android:layout_width="1dip"
android:layout_height="fill_parent"
android:background="#E3E0D5" />

<TextView
android:id="@+id/btn_ok"
style="@style/txt_titleStyle1"
android:layout_width="0.0dip"
android:layout_height="40dp"
android:layout_weight="1.0"
android:gravity="center"
android:text="确定"
android:textColor="@color/blue1"
android:textSize="16sp" />
LinearLayout>
LinearLayout>

LinearLayout>
看设计模式下比较清楚:
23、微信-温馨提示对话框WarnTipDialog_第1张图片

代码:
package com.example.wechat.dialog;

import android.content.Context;
import android.content.DialogInterface;
import android.view.View;
import android.widget.TextView;

import com.example.wechat.R;

/**
* Created by sing on 2016/2/15.
*/
public class WarnTipDialog extends BaseDialog implements View.OnClickListener {
private TextView btn_cancel, btn_ok;
private TextView mHtvText;
private String mText;
private static OnClickListener mOnClickListener;
private static BaseDialog mBaseDialog;// 当前的对话框

public WarnTipDialog(Context context, String text) {
super(context);
mText = text;
mBaseDialog = new BaseDialog(context);
init();
}

private void init() {
setContentView(R.layout.layout_dialog_warntip);
mHtvText = (TextView) findViewById(R.id.dialog_generic_htv_message);
mHtvText.setText(mText);
btn_cancel = (TextView) findViewById(R.id.btn_cancel);
btn_ok = (TextView) findViewById(R.id.btn_ok);
btn_cancel.setOnClickListener(this);
btn_ok.setOnClickListener(this);
}

public void setText(String text) {
if (text == null) {
mHtvText.setVisibility(View.GONE);
} else {
mText = text;
mHtvText.setText(mText);
}
}

public void setBtnOkLinstener(DialogInterface.OnClickListener listener) {
mOnClickListener = listener;
}

@Override
public void dismiss() {
if (isShowing()) {
super.dismiss();
}
}

@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_cancel:
if (isShowing()) {
super.dismiss();
}
break;

case R.id.btn_ok:
if (mOnClickListener != null) {
mOnClickListener.onClick(mBaseDialog, 1);
}
break;
}
}
}

你可能感兴趣的:(23、微信-温馨提示对话框WarnTipDialog)