android 他们定义对话框
创建一个布局文件 my_dialog.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
> <TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="4dp"
android:text="@string/textView1"
/> <EditText
android:id="@+id/editText_user"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/textView1"
android:layout_marginTop="4dp"
/> <TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/editText_user"
android:layout_below="@+id/editText_user"
android:layout_marginTop="7dp"
android:text="@string/textView2"
/> <EditText
android:id="@+id/editText_pwd"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView2"
android:layout_marginTop="4dp"
android:layout_below="@+id/textView2"
/>
</RelativeLayout>
下面是strings.xml文件:
<? xml version="1.0" encoding="utf-8"?>
<resources> <string name="app_name">demo091801</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string> <string name="MyDialog">自己定义对话框</string>
<string name="textView1">username</string> <string name="textView2">password</string> </resources>
在主activity_main.xml中加入一个button控件,当单击此button时即弹出自己定义的对话框:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" > <Button
android:id="@+id/My_Dialog"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/MyDialog"
/>
</RelativeLayout>
图形界面例如以下:
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbHAzMTAwMTg5MzE=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="">
在MainActivity.java代码中为button控件设置单击事件监听,并弹出自己定义的对话框:
MainActivity.java:
package com.example.demo091801; import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.view.LayoutInflater;
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 btn1 = (Button)findViewById(R.id.My_Dialog); btn1.setOnClickListener(new OnClickListener()
{ @Override
public void onClick(View arg0) {
// TODO Auto-generated method stub AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
LayoutInflater inflater = getLayoutInflater();
View view = inflater.inflate(R.layout.my_dialog, null); builder.setTitle("登陆");
builder.setView(view);
builder.setPositiveButton("登陆", new DialogInterface.OnClickListener() { @Override
public void onClick(DialogInterface arg0, int arg1) {
// TODO Auto-generated method stub }
}); builder.setNegativeButton("取消", new DialogInterface.OnClickListener() { @Override
public void onClick(DialogInterface arg0, int arg1) {
// TODO Auto-generated method stub }
}); AlertDialog dialog = builder.create();
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;
} }
作者:http://blog.csdn.net/lp310018931
版权声明:本文博主原创文章,博客,未经同意不得转载。
android 他们定义对话框的更多相关文章
- Android自己定义对话框实现QQ退出界面
效果 首先看下qq的效果图,点击菜单button后点退出就会出现如图的对话框. 从上图能够看出,该对话框有一个圆角,以及标题,提示信息,两个button,button颜色是白色,button点击后背景 ...
- Android课程---关于对话框的学习
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...
- 经常使用的android弹出对话框
我们在平时做开发的时候,免不了会用到各种各样的对话框,相信有过其它平台开发经验的朋友都会知道,大部分的平台都仅仅提供了几个最简单的实现,假设我们想实现自己特定需求的对话框,大家可能首先会想到,通过继承 ...
- Android 自学之对话框
Android为我们提供了丰富的对话框支持,提供了四种常用的对话框: AlertDialog:功能丰富.实际应用最广泛的对话框. ProgressDialog:进度对话框,该对话框只用于简单的进度条封 ...
- Android中的对话框AlertDialog使用技巧合集-转载
Android中的对话框AlertDialog使用技巧合集 文章来自:http://blog.csdn.net/blue6626/article/details/6641105 今天我用自 ...
- Android UI系列--对话框(一)(AlertDialog,TimePickerDialog,DatePickerDialog,ProgressDialog)
一.Dialog介绍 dialog就是一个在屏幕上弹出一个可以让用户做出一个选择,或者输入额外的信息的对话框,一个对话框并不会沾满我们整个的屏幕,并且通常用于模型事件当中需要用户做出一个决定后才会继续 ...
- Android自己定义dialog中的EditText无法弹出键盘的解决
近期我独立开发的项目<全医会>已经在内測其中了.非常快将会上架到各大应用市场.之前开发的几个项目都由于一些原因没有上架还是比較遗憾的.所以,近期我心情格外的好. 今天在做一个新项目,专为律 ...
- Android自己定义提示框
在开发中,假设感觉系统自带的提示框不好看,开发人员能够自定义提示框的样式.主要是继承Dialog 程序文件夹结构 关键代码 package com.dzt.custom.dialog; import ...
- Android自己定义矩形及selector、shape的使用
[声明]转载请注明出处.此文出自指尖飞落的博客:http://blog.csdn.net/huntersnail --每天写一篇博客.每天做一点技术积累! Android自己定义矩形及selector ...
随机推荐
- 成都Java培训机构太多,该如何选择呢?
Java培训的势头愈发火热.越来越多的人看到了Java培训的前途所在,可是最好的Java培训机构是哪家呢?如何推断一家Java培训机构的专业性呢?140610lscs" target=&qu ...
- DS Scheduler 0.7 发布,Linux 调度系统 - 开源中国社区
DS Scheduler 0.7 发布,Linux 调度系统 - 开源中国社区 DS Scheduler 0.7 发布,Linux 调度系统
- Linux 核心阅读工具vim+ctags+cscope+taglist
今天.介绍vim+ctags+cscope+taglist的内核阅读配置. 当使用过之后,我相信大部分人都会舍弃之前的Eclipse(我就是活生生的一个样例).我们先来看看实现的界面是怎么样的: 我们 ...
- php获取分类以下的全部子类方法
获取分类以下的全部子类方法: static function getMenuTree($arrCat, $parent_id = 0, $level = 0,$all=True) { static $ ...
- SqlServer操作远程数据库
exec sp_addlinkedserver 'srv2','','mssql2008','服务器IP' exec sp_addlinkedsrvlogin 'srv2','false',null, ...
- SE 2014年5月5日
如图配置 某企业网络规划图(三台交换设备/三台路由设备) 接入层 SW1 连接终端用户 汇聚层 SW2 SW3 核心层 R1 R2 R5 1. 如图 SW1 SW2 SW3 物理链路两两相连接,网络中 ...
- python学习1(小白记录)
python创建cocos2d-x项目注意点1. 2.7.5版本号的.配置好环境变量之后.要切换到tools文件夹下.直接运行 python create_project.py ..........这 ...
- android中用get和post方式向服务器提交请求
通过get和post方式向服务器发送请求首先说一下get和post的区别get请求方式是将提交的参数拼接在url地址后面,例如http://www.baidu.com/index.jsp?num=23 ...
- Codeforces Jzzhu and Sequences(圆形截面)
# include <stdio.h> int f[10]; int main() { int x,y,n,j; while(~scanf("%d%d%d",& ...
- .Net程序猿玩转Android开发---(7)相对布局RelativeLayout
相对布局RelativeLayout是Android布局中一个比較经常使用的控件,使用该控件能够布局出适合各种屏幕分辨率的布局,RelativeLayout採用相对位置进行 ...