自定义dialog

第一:首先是自定义的样式:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <LinearLayout<pre name="code" class="html">
android:layout_width="match_parent" android:layout_height="30dp" android:gravity="center" android:orientation="vertical" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="提示" /> </LinearLayout> <View android:id="@+id/viewxian" android:layout_width="match_parent" android:layout_height="1dp" android:background="#000000" /> <LinearLayout android:layout_width="match_parent" android:layout_height="60dp" android:gravity="center_vertical" android:orientation="vertical" > <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="确定退出百度地图?" /> </LinearLayout> <View android:id="@+id/viewxian2" android:layout_width="match_parent" android:layout_height="1dp" android:background="#89D549" /> <LinearLayout android:layout_width="match_parent" android:layout_height="50dp" > <TextView android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="match_parent" android:gravity="center" android:layout_weight="1" android:textColor="#89D549" android:text="取消" /> <View android:id="@+id/aa" android:layout_width="1dp" android:layout_height="match_parent" android:background="#89D549" /> <TextView android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_weight="1" android:gravity="center" android:text="确定" /> </LinearLayout></LinearLayout>
 
</pre><pre name="code" class="html">
<span style="font-size:24px;color:#ff0000;"><strong>第二:然后写一个自定义的MyDialog的类,继承系统的dialog:</strong></span>
</pre><pre name="code" class="html"><pre name="code" class="html">package com.example.didingyidialog;


import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;

public class Mydialog extends Dialog{

	public Mydialog(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
	}

	public Mydialog(Context context, boolean cancelable,
			OnCancelListener cancelListener) {
		super(context, cancelable, cancelListener);
		// TODO Auto-generated constructor stub
	}

	public Mydialog(Context context, int theme) {
		super(context, theme);
		// TODO Auto-generated constructor stub
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.mydialoga);
	}

}


 
<span style="font-size:24px;color:#ff0000;"><strong>第三:调用,在什么地方调用。一个活动中的例子</strong></span>
<span style="font-size:24px;color:#ff0000;"><strong>
</strong></span>
</pre><pre name="code" class="html">package com.example.didingyidialog;

import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button but=(Button)findViewById(R.id.button1xianshi);
        but.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				Mydialog dialog=new Mydialog(MainActivity.this,R.style.MyDialog);
				dialog.show();
			}
		});
        
    }


    @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;
    }
    
}
附加:当然里边有个一个Style,样式
<style name="MyDialog" parent="@android:style/Theme.Dialog">
        <item name="android:windowFrame">@null</item>
        <!-- 边框 -->
        <item name="android:windowIsFloating">true</item>
        <!-- 是否浮现在activity之上 -->
        <item name="android:windowIsTranslucent">false</item>
        <!-- 半透明 -->
        <item name="android:windowNoTitle">true</item>
        <!-- 无标题 -->
       <!--  <item name="android:windowBackground">@drawable/ic_launcher</item> -->
        <!-- 背景透明 -->
        <item name="android:backgroundDimEnabled">false</item>
        <!-- 模糊 -->

    </style>

现在一个,完整的dialog就完成了
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值