android自定义弹出层

DialogShow.java
01 package com.asfman;
02
03 import android.app.Activity;
04 import android.os.Bundle;
05 import android.view.View;
06 import android.widget.Button;
07
08 public class DialogShow extends Activity {
09
10 /** Called when the activity is first created. */
11 @Override
12 public void onCreate(Bundle savedInstanceState) {
13 super.onCreate(savedInstanceState);
14 setContentView(R.layout.main);
15 Button btn = (Button) findViewById(R.id.button1);
16 btn.setOnClickListener(new Button.OnClickListener() {
17
18 @Override
19 public void onClick(View v) {
20 // TODO Auto-generated method stub
21 new Tip(DialogShow.this).show();
22 }
23
24 });
25 }
26 }

[代码] Tip.java

01 package com.asfman;
02
03 import android.app.Dialog;
04 import android.content.Context;
05 import android.view.Gravity;
06 import android.view.View;
07 import android.view.ViewGroup;
08 import android.view.Window;
09 import android.view.WindowManager;
10 import android.widget.ImageView;
11
12 public class Tip {
13
14 private ImageView image;
15 private Dialog mDialog;
16
17 public Tip(Context context) {
18 mDialog = new Dialog(context, R.style.dialog);
19 Window window = mDialog.getWindow();
20 WindowManager.LayoutParams wl = window.getAttributes();
21 wl.x = -30;
22 wl.y = 20;
23 window.setAttributes(wl);
24 window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
25 WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
26 //window.setGravity(Gravity.CENTER);
27 window.setLayout(ViewGroup.LayoutParams.FILL_PARENT,
28 ViewGroup.LayoutParams.WRAP_CONTENT);
29 mDialog.setContentView(R.layout.tip);
30 mDialog.setFeatureDrawableAlpha(Window.FEATURE_OPTIONS_PANEL, 0);
31 image = (ImageView) mDialog.findViewById(R.id.image);
32 image.setOnClickListener(new ImageView.OnClickListener() {
33 @Override
34 public void onClick(View arg0) {
35 mDialog.dismiss();
36 }
37 });
38 }
39
40 public void show() {
41 mDialog.show();
42 }
43
44 }

[代码] dialog.xml

01 <?xml version="1.0" encoding="utf-8"?>
02 <resources>
03 <style name="dialog" parent="@android:style/Theme.Dialog">
04 <!-- <item name="android:windowFrame">@null</item> -->
05 <!-- <item name="android:windowIsFloating">true</item> -->
06 <!-- <item name="android:windowIsTranslucent">false</item> -->
07 <item name="android:windowNoTitle">true</item>
08 <item name="android:windowBackground">@null</item>
09 <!-- <item name="android:backgroundDimEnabled">false</item> -->
10 </style>
11 </resources>

[代码] tip.xml

01 <?xml version="1.0" encoding="utf-8"?>
02 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
03 android:layout_width="300dp" android:layout_height="190dp"
04 android:orientation="vertical" android:background="@drawable/blueinfowindow">
05 <LinearLayout android:layout_width="fill_parent"
06 android:layout_height="wrap_content" android:orientation="horizontal"
07 android:id="@+id/upContent" android:layout_marginTop="30dp"
08 android:layout_marginLeft="30dp">
09 <TextView android:id="@+id/description" android:layout_width="220dp"
10 android:layout_height="wrap_content"
11 android:text="1.this is the test text!\n
12 1.this is the test text!\n1.this is the test text!\n1.this is the test text!\n" android:textColor="#000000" />
13 <ImageView android:id="@+id/image" android:background="@drawable/icon" android:layout_width="wrap_content" android:layout_height="wrap_content"/>
14 </LinearLayout>
15 </LinearLayout>
posted @ 2012-04-24 23:40  周文  阅读(740)  评论(0编辑  收藏  举报