转载请注明:http://blog.csdn.net/u012975705/article/details/49530733
SimpleConfirmDialog.java
public class SimpleConfirmDialog extends Dialog implements View.OnClickListener {
//提示语
private TextView mSlogan;
//取消按钮
private Button mCancel;
//确认按钮
private Button mConfirm;
// private MyCollectionActivity mActivity;
private OnConfirmListener mListener;
public SimpleConfirmDialog(Context context) {
super(context, R.style.Theme_Light_FullScreenDialogAct);
setContentView(R.layout.dialog_simple_confirm);
initView();
initData();
initEvent();
}
@Override
public void show() {
super.show();
// WindowManager m = mActivity.getWindowManager();
// Display d = m.getDefaultDisplay(); // 获取屏幕宽、高用
// WindowManager.LayoutParams p = getWindow().getAttributes(); // 获取对话框当前的参数值
// p.height = 270;
// p.width = 140;
// getWindow().setAttributes(p);
}
/**
* 初始化视图
*/
private void initView() {
mSlogan = (TextView) findViewById(R.id.simple_dialog_slogan);
mCancel = (Button) findViewById(R.id.simple_dialog_cancel);
mConfirm = (Button) findViewById(R.id.simple_dialog_confirm);
}
/**
* 初始化控件、数据
*/
private void initData() {
}
/**
* 初始化事件
*/
private void initEvent() {
mCancel.setOnClickListener(this);
mConfirm.setOnClickListener(this);
}
public void setClickListener(String slogan, OnConfirmListener mListener) {
mSlogan.setText(slogan);
this.mListener = mListener;
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.simple_dialog_cancel:
cancel();
break;
case R.id.simple_dialog_confirm:
mListener.onConfirm();
break;
default:
break;
}
}
public interface OnConfirmListener {
void onConfirm();
}
}
style:
<style name="BaseDialog" parent="@android:style/Theme.Dialog" />
<style name="Theme.Light.FullScreenDialogAct" parent="@style/BaseDialog">
<item name="android:windowBackground">@color/transparent</item>
<item name="android:windowFrame">@null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:textSize">16.0sp</item>
<item name="android:textColor">#ff555555</item>
<item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:windowSoftInputMode">adjustPan</item>
</style>
xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:background="@drawable/bg_simple_dialog"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="20dp">
<TextView
android:id="@+id/simple_dialog_slogan"
style="@style/TextTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="提示语" />
</LinearLayout>
<View
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:background="@color/background"
android:layout_width="match_parent"
android:layout_height="1dp"/>
<LinearLayout
android:padding="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_marginRight="5dp"
android:gravity="center"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
<Button
style="@style/TextNormal"
android:text="取消"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:id="@+id/simple_dialog_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/bg_dialog_button_cancel" />
</LinearLayout>
<LinearLayout
android:layout_marginLeft="5dp"
android:gravity="center"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
<Button
android:textColor="@color/white"
style="@style/TextTitle"
android:text="确定"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:id="@+id/simple_dialog_confirm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/bg_dialog_button_confirm" />
</LinearLayout>
</LinearLayout>
</LinearLayout>