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 ...
随机推荐
- hdu 4970 Killing Monsters(数学题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4970 Problem Description Kingdom Rush is a popular TD ...
- 008实现一个算法从一个单链表中返回倒数第n个元素(keep it up)
我们维护两个指针, 它们之间的距离为n. 然后.我将这两个指针同步地在这个单链表上移动,保持它们的距离 为n不变. 那么, 当第二个指针指到空时.第一个指针即为所求. #include <ios ...
- CH BR4思考熊(恒等有理式-逆波兰表达式求值)
恒等有理式 总时限 10s 内存限制 256MB 出题人 fotile96 提交情况 4/43 描述 给定两个有理式f(X)与g(X),判断他们是否恒等(任意A,如果f(A)与g(A)均有定义,那么f ...
- C++ Preprosessor import
#import Attributes Provides links to attributes used with the #import directive. Microsoft Specific ...
- linux crontab定时执行shell脚本
linux下使用crontab命令被用来提交和管理用户的需要周期性执行的任务,示例如下:crontab -e 编辑周期任务30 21 * * * /etc/init.d/smb restart 每晚的 ...
- LAMP配置参考地址
http://www.linuxidc.com/Linux/2014-07/104563.htm
- 微信简单Demo
新建一个WxHandler.ashx public class WxHandler : IHttpHandler { public static string Msg; public void Pro ...
- 流动python - 一个极简主义event制
event至少该系统的核心,以满足: 1.存储容器事件,可以被添加到事件来删除 2.触发事件fire 守则. class Event(list): def __call__(self, *args, ...
- MySQL 触发器例子(两张表同步增加和删除)
以下两个例子来自:http://www.cnblogs.com/nicholas_f/archive/2009/09/22/1572050.html实测有效,但是原帖的分隔符不正确,因此稍作修改.其中 ...
- tarjan+缩点
B - Popular Cows Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Su ...