android自定义弹出层

来源:互联网 发布:linux gem命令 编辑:程序博客网 时间:2024/05/25 23:57

1. [代码]DialogShow.java     跳至 [1] [2] [3] [4] [全屏预览]

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

2. [代码]Tip.java     跳至 [1] [2] [3] [4] [全屏预览]

view source
print?
01package com.asfman;
02  
03import android.app.Dialog;
04import android.content.Context;
05import android.view.Gravity;
06import android.view.View;
07import android.view.ViewGroup;
08import android.view.Window;
09import android.view.WindowManager;
10import android.widget.ImageView;
11  
12public class Tip {
13  
14    privateImageView image;
15    privateDialog mDialog;
16  
17    publicTip(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(newImageView.OnClickListener() {
33            @Override
34            publicvoid onClick(View arg0) {
35                mDialog.dismiss();
36            }
37        });
38    }
39  
40    publicvoid show() {
41        mDialog.show();
42    }
43  
44}

3. [代码]dialog.xml     跳至 [1] [2] [3] [4] [全屏预览]

view source
print?
01<?xmlversion="1.0"encoding="utf-8"?>
02<resources>
03    <stylename="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        <itemname="android:windowNoTitle">true</item>
08        <itemname="android:windowBackground">@null</item>
09<!--         <item name="android:backgroundDimEnabled">false</item> -->
10    </style>
11</resources>

4. [代码]tip.xml     跳至 [1] [2] [3] [4] [全屏预览]

view source
print?
01<?xmlversion="1.0"encoding="utf-8"?>
02<LinearLayoutxmlns: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    <LinearLayoutandroid: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        <TextViewandroid: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        <ImageViewandroid:id="@+id/image"android:background="@drawable/icon"android:layout_width="wrap_content"android:layout_height="wrap_content"/>    
14    </LinearLayout>
15</LinearLayout>
原创粉丝点击