本文实例讲述了Android编程自定义扁平化对话框。分享给大家供大家参考,具体如下:

平时我们开发的大多数的Android、iOS的APP,它们的风格都是拟物化设计。如Android 4.X、iOS 7、WP8采用的是扁平化设计,可以看出扁平化设计是未来UI设计的趋势。其实扁平化设计要比拟物化设计要简单一点,扁平化设计更加的简约,给人视觉上更加舒服。
Shamoo想到在Android平台上弄一个扁平化的对话框。参考过一篇帖子,然后改了一下。
这个Demo比较简单,首先是一个dialog的布局文件,这个dialog的布局要实例化成对话框可以通过AlertDialog.Builder的setView方法,将LayoutInflater实例化的dialog布局设置对话框具体显示内容。效果图如下:
下面直接贴代码
DialogWindows.Java
package com.example.dialogwindows;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.Toast;
public class DialogWindows extends Activity {
private Button button;
private View dialogView;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
button = (Button) findViewById(R.id.btn);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Builder builder = myBuilder(DialogWindows.this);
final AlertDialog dialog = builder.show();
//点击屏幕外侧,dialog不消失
dialog.setCanceledOnTouchOutside(false);
Button btnOK = (Button) dialogView.findViewById(R.id.btn_ok);
btnOK.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Toast.makeText(DialogWindows.this, "你点击了确定按钮", Toast.LENGTH_SHORT).show();
dialog.dismiss();
}
});
Button btnCancel = (Button) dialogView.findViewById(R.id.btn_cancel);
btnCancel.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Toast.makeText(DialogWindows.this, "你点击了取消按钮", Toast.LENGTH_SHORT).show();
dialog.dismiss();
}
});
ImageButton customviewtvimgCancel = (ImageButton) dialogView.findViewById(R.id.btn_exit);
customviewtvimgCancel.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Toast.makeText(DialogWindows.this, "你点击了退出按钮", Toast.LENGTH_SHORT).show();
dialog.dismiss();
}
});
}
});
}
protected Builder myBuilder(Context context) {
LayoutInflater inflater = getLayoutInflater();
AlertDialog.Builder builder = new AlertDialog.Builder(context);
dialogView = inflater.inflate(R.layout.dialog, null);
return builder.setView(dialogView);
}
}
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"
android:orientation="vertical" >
<!-- 标题栏 -->
<RelativeLayout
android:id="@+id/dialog_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#1A94F9" >
<TextView
android:id="@+id/tv_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:padding="10dp"
android:text="@string/about"
android:textColor="#000000" />
<ImageButton
android:id="@+id/btn_exit"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:background="@drawable/canceltor" />
</RelativeLayout>
<!-- 显示的内容 -->
<LinearLayout
android:id="@+id/dialog_msg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_below="@id/dialog_title"
android:padding="20dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/author"
android:textColor="#ffffff" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:linksClickable="true"
android:text="@string/blog"
android:textColor="#ffffff" />
</LinearLayout>
<!-- 底部按钮 -->
<LinearLayout
android:id="@+id/customviewlayLink"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/dialog_msg"
android:orientation="horizontal"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:paddingBottom="20dp" >
<Button
android:id="@+id/btn_ok"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:background="@drawable/linkbtnbged"
android:linksClickable="true"
android:layout_weight="1"
android:layout_marginRight="10dp"
android:text="@string/btn_ok" />
<Button
android:id="@+id/btn_cancel"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:linksClickable="true"
android:background="@drawable/linkbtnbged"
android:text="@string/btn_cancel"
android:layout_marginLeft="10dp"
android:layout_weight="1" />
</LinearLayout>
</RelativeLayout>
main.xml
<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" >
<Button
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="@string/show_dialog" />
</RelativeLayout>
更多关于Android相关内容感兴趣的读者可查看本站专题:《Android开发入门与进阶教程》、《Android调试技巧与常见问题解决方法汇总》、《Android基本组件用法总结》、《Android视图View技巧总结》、《Android布局layout技巧总结》及《Android控件用法总结》
希望本文所述对大家Android程序设计有所帮助。
# Android
# 对话框
# Android自定义EditText实现登录界面
# Android取消EditText自动获取焦点默认行为
# Android控件系列之EditText使用方法
# android同时控制EditText输入字符个数和禁止特殊字符输入的方法
# Android中EditText实现不可编辑解决办法
# Android定制自己的EditText轻松改变底线颜色
# Android中EditText显示明文与密码的两种方式
# Android更改EditText下划线颜色样式的方法
# android基础教程之android的listview与edittext冲突解决方法
# Android EditText实现扁平化的登录界面
# 扁平化
# 的是
# 都是
# 是一个
# 进阶
# 相关内容
# 感兴趣
# 可以通过
# 给人
# 给大家
# 自定义
# 要比
# 可以看出
# 更多关于
# 改了
# 解决方法
# 所述
# 程序设计
# 标题栏
相关文章:
如何选择适合PHP云建站的开源框架?
实例解析Array和String方法
宝塔Windows建站如何避免显示默认IIS页面?
建站之星北京办公室:智能建站系统与小程序生成方案解析
定制建站模板如何实现SEO优化与智能系统配置?18字教程
网站建设制作、微信公众号,公明人民医院怎么在网上预约?
已有域名如何免费搭建网站?
网站制作软件有哪些,制图软件有哪些?
成都网站制作价格表,现在成都广电的单独网络宽带有多少的,资费是什么情况呢?
佛山网站制作系统,佛山企业变更地址网上办理步骤?
专业商城网站制作公司有哪些,pi商城官网是哪个?
清单制作人网站有哪些,近日“兴风作浪的姑奶奶”引起很多人的关注这是什么事情?
沈阳个人网站制作公司,哪个网站能考到沈阳事业编招聘的信息?
关于BootStrap modal 在IOS9中不能弹出的解决方法(IOS 9 bootstrap modal ios 9 noticework)
建站10G流量真的够用吗?如何应对访问高峰?
品牌网站制作公司有哪些,买正品品牌一般去哪个网站买?
视频网站制作教程,怎么样制作优酷网的小视频?
如何在建站宝盒中设置产品搜索功能?
如何撰写建站申请书?关键要点有哪些?
深圳企业网站制作设计,在深圳如何网上全流程注册公司?
mc皮肤壁纸制作器,苹果平板怎么设置自己想要的壁纸我的世界?
c# Task.Yield 的作用是什么 它和Task.Delay(1)有区别吗
建站主机选哪种环境更利于SEO优化?
高端建站如何打造兼具美学与转化的品牌官网?
用v-html解决Vue.js渲染中html标签不被解析的问题
音响网站制作视频教程,隆霸音响官方网站?
免费视频制作网站,更新又快又好的免费电影网站?
西安市网站制作公司,哪个相亲网站比较好?西安比较好的相亲网站?
如何快速生成专业多端适配建站电话?
C++用Dijkstra(迪杰斯特拉)算法求最短路径
电脑免费海报制作网站推荐,招聘海报哪个网站多?
定制建站策划方案_专业建站与网站建设方案一站式指南
如何通过商城免费建站系统源码自定义网站主题?
如何通过多用户协作模板快速搭建高效企业网站?
定制建站价位费用解析与套餐推荐全攻略
建站之星安装需要哪些步骤及注意事项?
高防服务器租用指南:配置选择与快速部署攻略
家具网站制作软件,家具厂怎么跑业务?
*服务器网站为何频现安全漏洞?
如何在建站之星绑定自定义域名?
香港服务器部署网站为何提示未备案?
单页制作网站有哪些,朋友给我发了一个单页网站,我应该怎么修改才能把他变成自己的呢,请求高手指点迷津?
如何在IIS管理器中快速创建并配置网站?
TestNG的testng.xml配置文件怎么写
网站建设设计制作营销公司南阳,如何策划设计和建设网站?
如何通过wdcp面板快速创建网站?
实现虚拟支付需哪些建站技术支撑?
专业企业网站设计制作公司,如何理解商贸企业的统一配送和分销网络建设?
已有域名和空间如何搭建网站?
建站之星如何防范黑客攻击与数据泄露?
*请认真填写需求信息,我们会在24小时内与您取得联系。