AlertDialog自定义
2016-06-02 15:06
357 查看
<?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 android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="用户名"/> <EditText android:layout_width="wrap_content" android:layout_height="wrap_content"/> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="密码"/> <EditText android:layout_width="wrap_content" android:layout_height="wrap_content"/> </LinearLayout> </LinearLayout>
package com.pingyijinren.helloworld.activity; import android.content.DialogInterface; import android.support.v7.app.AlertDialog; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.KeyEvent; import android.view.View; import android.widget.Button; import com.pingyijinren.helloworld.R; public class MainActivity extends AppCompatActivity implements View.OnClickListener { private AlertDialog alertDialog; private Button button; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); button=(Button)findViewById(R.id.button); button.setOnClickListener(this); } @Override public void onClick(View v) { AlertDialog.Builder builder=new AlertDialog.Builder(this); builder.setIcon(R.mipmap.ic_launcher); builder.setTitle("用户登录"); builder.setView(R.layout.alert_dialog_layout); builder.setPositiveButton("退出", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { finish(); } }); builder.setNegativeButton("取消", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); alertDialog=builder.create(); alertDialog.show(); } }
相关文章推荐
- 跟我一起学Microsoft SQL Server 2012 Internals(3.4)
- 神经网络机器翻译Neural Machine Translation(4): Modeling Coverage & MRT
- SAP携手NBA 中国在华推出 NBA.com/Stats
- Sicily1443—— Printer Queue
- 2016年中小总结
- 建造者模式(生成器模式)
- Android应用开发之自动更新不用愁
- iOS开发UI篇—实现一个简单的手势解锁应用(基本)
- scala集合
- iOS 基础篇4—懒加载
- swift学习日志—— if let 与 guard 语法糖
- CSS绘图:墙
- Jquery图片上传大小限制
- LeetCode459. Repeated Substring Pattern
- JavaScript学习笔记(1)
- 有趣的数列[HNOI2009][Codevs2337]
- 学习内容DPDK
- iOS开发系列--UITableView全面解析
- C++ 引用
- Lua模拟继承行为