Android学习之Activity弹窗

WindowDemo.java:

package org.lee.android;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;

public class WindowDemo extends Activity{
	private ImageButton mybut;

    @Override  
    public void onCreate(Bundle savedInstanceState) {  
        super.onCreate(savedInstanceState);  
        super.setContentView(R.layout.window_demo);       // 默认布局管理器  
        this.mybut = (ImageButton) super.findViewById(R.id.right_btn); // 取得按钮  
        this.mybut.setOnClickListener(new OnClickListenerImpl()); // 设置事件类 
    }
    
    private class OnClickListenerImpl implements OnClickListener {  
    	  
        @Override  
		public void onClick(View view) {
        	Intent intent = new Intent (WindowDemo.this,MainTopRightDialog.class);			
    		startActivity(intent);
		}
    }

}

MainTopRightDialog.java:

package org.lee.android;


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import android.widget.Toast;

public class MainTopRightDialog extends Activity {
	//private MyDialog dialog;
	private LinearLayout layout;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main_top_right_dialog);
		//dialog=new MyDialog(this);
		layout=(LinearLayout)findViewById(R.id.main_dialog_layout);
		layout.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Toast.makeText(getApplicationContext(), "提示:点击窗口外部关闭窗口!", 
						Toast.LENGTH_SHORT).show();	
			}
		});
	}

	@Override
	public boolean onTouchEvent(MotionEvent event){
		finish();
		return true;
	}
	/*
	public void exitbutton1(View v) {  
    	this.finish();    	
      }  
	public void exitbutton0(View v) {  
    	this.finish();
    	MainWeixin.instance.finish();//关闭Main 这个Activity
      }  
	*/
}

styles.xml:

<resources xmlns:android="http://schemas.android.com/apk/res/android">

    <style name="AnimTop2" parent="@android:style/Animation">
        <item name="android:windowEnterAnimation">@anim/push_top_in2</item>
        <item name="android:windowExitAnimation">@anim/push_top_out2</item>
    </style>

    <style name="MyDialogStyleTop" parent="android:Theme.Dialog">
        <item name="android:windowAnimationStyle">@style/AnimTop2</item>
        <item name="android:windowFrame">@null</item>
 		<!-- 边框 -->
        <item name="android:windowIsFloating">true</item>
 		<!-- 是否浮现在activity之上 -->
        <item name="android:windowIsTranslucent">true</item>
 		<!-- 半透明 -->
        <item name="android:windowNoTitle">true</item>
 		<!-- 无标题 -->
        <item name="android:windowBackground">@android:color/transparent</item>
 		<!-- 背景透明 -->
        <item name="android:backgroundDimEnabled">false</item>
 		<!-- 模糊 -->
    </style>

</resources>

push_top_in2.xml:

<?xml version="1.0" encoding="utf-8"?>
<!-- 上下滑入式 -->
<scale   xmlns:android="http://schemas.android.com/apk/res/android"
        android:interpolator="@android:anim/accelerate_decelerate_interpolator"  
        android:fromXScale="1.0"   
        android:toXScale="1.0"   
        android:fromYScale="0"   
        android:toYScale="1.0"   
        android:pivotX="0"  
        android:pivotY="10%"  
        android:duration="200" />

push_top_out2.xml:

<?xml version="1.0" encoding="utf-8"?>

<scale   xmlns:android="http://schemas.android.com/apk/res/android"
        android:interpolator="@android:anim/accelerate_decelerate_interpolator"  
        android:fromXScale="1.0"   
        android:toXScale="1.0"   
        android:fromYScale="1.0"   
        android:toYScale="0"   
        android:pivotX="0"  
        android:pivotY="10%"  
        android:duration="200" />
<!-- MainTopRightDialog测试 -->
        <activity
            android:name=".MainTopRightDialog"
            android:theme="@style/MyDialogStyleTop"
            android:screenOrientation="sensor"  
            android:configChanges="orientation|keyboardHidden" >
            <intent-filter>
                <action android:name="android.intent.action.maintoprightdialog" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

 Android学习之Activity弹窗

相关推荐