android自定义弹出层

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

01package com.asfman;
02  
03import android.app.Activity;
04import android.os.Bundle;
05import android.view.View;
06import android.widget.Button;
07  
08public 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}

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

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    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}

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

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>

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

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>
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值