【实例简介】
【实例截图】
【核心代码】
package com.example.startdialog;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.Display;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
public class MainActivity extends Activity {
// BaseDialog dia;
Dialog dia;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/*
* LayoutInflater inflater2 = LayoutInflater.from(MainActivity.this);
* View merge_view = inflater2.inflate(R.layout.activity_start_dialog,
* null); dia = new BaseDialog(MainActivity.this, merge_view,
* R.style.dialog_style); dia.show();
*/
Context context = MainActivity.this;
dia = new Dialog(context, R.style.edit_AlertDialog_style);
dia.setContentView(R.layout.activity_start_dialog);
/*WindowManager wm = (WindowManager)MainActivity.this.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
int width = display.getWidth();
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.splash);
ImageView imageView =(ImageView)dia.findViewById(R.id.start_img);
setImageData(imageView,bitmap,width);*/
Button mClose_btn = (Button) dia.findViewById(R.id.btn_close);
mClose_btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
dia.cancel();// 关闭弹出框
}
});
dia.show();
dia.setCanceledOnTouchOutside(false); // Sets whether this dialog is
// canceled when touched outside
// the window's bounds.
Window w = dia.getWindow();
WindowManager.LayoutParams lp = w.getAttributes();
lp.x = 0;
lp.y = 40;
dia.onWindowAttributesChanged(lp);
}
/*private void setImageData(ImageView imageView, Bitmap bitmap, int width) {
// TODO Auto-generated method stub
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(width,bitmap.getHeight()*width/bitmap.getWidth());
imageView.setLayoutParams(params);
imageView.setScaleType(ScaleType.FIT_XY);
imageView.setPadding(0, 0, 0, 5);
imageView.setImageBitmap(bitmap);
}*/
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}