正常的Dialog弹出窗口,当点击窗口外围时关闭弹出的窗口,这个在很多弹出式的Activity上很为实用!
dialog.xml 弹出窗口的界面布局:
弹出窗口的Activity:
- package com.xmz.activity;
- import android.app.Activity;
- import android.os.Bundle;
- import android.view.MotionEvent;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.widget.LinearLayout;
- public class DialogActivity extends Activity {
- private MyDialog dialog;
- private LinearLayout layout;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.dailog);
- dialog = new MyDialog(this);
- layout = (LinearLayout) findViewById(R.id.layout);
- layout.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- // TODO Auto-generated method stub
- }
- });
- }
- @Override
- public boolean onTouchEvent(MotionEvent event) {
- finish();
- return true;
- }
- }
复制代码
|
|