android自定义 dialog,android Dialog 自定义弹出层

DialogShow.java

Java代码

package com.asfman;

import android.app.Activity;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

public class DialogShow extends Activity {

/** *//** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

Button btn = (Button) findViewById(R.id.button1);

btn.setOnClickListener(new Button.OnClickListener() {

@Override

public void onClick(View v) {

// TODO Auto-generated method stub

new Tip(DialogShow.this).show();

}

});

}

}

Tip.java

Java代码

package com.asfman;

import android.app.Dialog;

import android.content.Context;

import android.view.Gravity;

import android.view.View;

import android.view.ViewGroup;

import android.view.Window;

import android.view.WindowManager;

import android.widget.ImageView;

public class Tip {

private ImageView image;

private Dialog mDialog;

public Tip(Context context) {

mDialog = new Dialog(context, R.style.dialog);

Window window = mDialog.getWindow();

WindowManager.LayoutParams wl = window.getAttributes();

wl.x = -30;

wl.y = 20;

window.setAttributes(wl);

window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,

WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);

//window.setGravity(Gravity.CENTER);

window.setLayout(ViewGroup.LayoutParams.FILL_PARENT,

ViewGroup.LayoutParams.WRAP_CONTENT);

mDialog.setContentView(R.layout.tip);

mDialog.setFeatureDrawableAlpha(Window.FEATURE_OPTIONS_PANEL, 0);

image = (ImageView) mDialog.findViewById(R.id.image);

image.setOnClickListener(new ImageView.OnClickListener() {

@Override

public void onClick(View arg0) {

mDialog.dismiss();

}

});

}

public void show() {

mDialog.show();

}

}

dialog.xml

Java代码

true

@null

tip.xml

Java代码

android:layout_width="300dp"android:layout_height="190dp"

android:orientation="vertical"android:background="@drawable/blueinfowindow">

android:layout_height="wrap_content"android:orientation="horizontal"

android:id="@+id/upContent"android:layout_marginTop="30dp"

android:layout_marginLeft="30dp">

android:layout_height="wrap_content"

android:text="1.thisis the test text!\n

1.thisis the test text!\n1.thisis the test text!\n1.thisis the test text!\n" android:textColor="#000000" />

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值