android仿IOS底部弹对话框

来源:互联网 发布:大数据 涂子沛 epub 编辑:程序博客网 时间:2024/05/02 00:37

在Android开发过程中,常常会因为感觉Android自带的Dialog的样式很丑,项目开发过程中会影响整体效果,会使得开发过程很是忧伤....(话唠时间结束!)

本文我将介绍一款开源的Dialog仿IOS底部弹窗效果IOS_Dialog_Library的使用。我将通过几个简单的示例介绍IOS_Dialog_Library.zip的使用方法。

1、IOS_Dialog_Library是开源的Dialog框架,所以首先你得下载IOS_Dialog_Library.zip包,并作为Library引入你的项目(引入过程省略)。

IOS_Dialog_Library下载地址:http://download.csdn.net/detail/u012721519/9500971


2、在创建完项目和引用完 IOS_Dialog_Library.zip 之后,开始编写代码。

activity_main.xml

<LinearLayout 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"    tools:context=".MainActivity"    android:orientation="vertical">    <Button        android:id="@+id/btn1"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:text="消息" />    <Button        android:id="@+id/btn2"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:text="图片" />    <Button        android:id="@+id/btn3"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:text="列表Item" />    <Button        android:id="@+id/btn4"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:text="退出 弹窗" />    <Button        android:id="@+id/btn5"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:text="错误提示窗口" /></LinearLayout>

上面主要是5个Button,即演示五种不同的IOS_Dialog_Library的使用方法。


MainActivity.java

package example.com.showdialog;import android.app.Activity;import android.os.Bundle;import android.view.View;import android.widget.Button;import zhangphil.iosdialog.widget.ActionSheetDialog;import zhangphil.iosdialog.widget.AlertDialog;/** * package:example.com.showdialog * name:MainActivity.java * Write by Jimmy.li * Date:2016/4/24 16:39 */public class MainActivity extends Activity implements View.OnClickListener {    private Button btn1, btn2, btn3, btn4, btn5;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        initView();    }    private void initView() {        btn1 = (Button) findViewById(R.id.btn1);        btn2 = (Button) findViewById(R.id.btn2);        btn3 = (Button) findViewById(R.id.btn3);        btn4 = (Button) findViewById(R.id.btn4);        btn5 = (Button) findViewById(R.id.btn5);        btn1.setOnClickListener(this);        btn2.setOnClickListener(this);        btn3.setOnClickListener(this);        btn4.setOnClickListener(this);        btn5.setOnClickListener(this);    }    @Override    public void onClick(View v) {        switch (v.getId()) {            case R.id.btn1:                new ActionSheetDialog(MainActivity.this)                        .builder()                        .setTitle("清空消息列表后,聊天记录依然保留,确定要清空消息列表?")                        .setCancelable(true)                        .setCanceledOnTouchOutside(true)                        .addSheetItem("清空消息列表", ActionSheetDialog.SheetItemColor.Red                                , new ActionSheetDialog.OnSheetItemClickListener() {                            @Override                            public void onClick(int which) {                                //填写事件                            }                        }).show();                break;            case R.id.btn2:                new ActionSheetDialog(MainActivity.this)                        .builder()                        .setCancelable(true)                        .setCanceledOnTouchOutside(true)                        .addSheetItem("发送给好友",                                ActionSheetDialog.SheetItemColor.Blue,                                new ActionSheetDialog.OnSheetItemClickListener() {                                    @Override                                    public void onClick(int which) {                                        //填写事件                                    }                                })                        .addSheetItem("转载到空间相册",                                ActionSheetDialog.SheetItemColor.Blue,                                new ActionSheetDialog.OnSheetItemClickListener() {                                    @Override                                    public void onClick(int which) {                                        //填写事件                                    }                                })                        .addSheetItem("上传到群相册",                                ActionSheetDialog.SheetItemColor.Blue,                                new ActionSheetDialog.OnSheetItemClickListener() {                                    @Override                                    public void onClick(int which) {                                        //填写事件                                    }                                })                        .addSheetItem("保存到手机",                                ActionSheetDialog.SheetItemColor.Blue,                                new ActionSheetDialog.OnSheetItemClickListener() {                                    @Override                                    public void onClick(int which) {                                        //填写事件                                    }                                }).show();                break;            case R.id.btn3:                new ActionSheetDialog(MainActivity.this)                        .builder()                        .setTitle("好友列表")                        .setCancelable(true)                        .setCanceledOnTouchOutside(true)                        .addSheetItem("删除好友", ActionSheetDialog.SheetItemColor.Red                                , new ActionSheetDialog.OnSheetItemClickListener() {                            @Override                            public void onClick(int which) {                                //填写事件                            }                        })                        .addSheetItem("增加好友", ActionSheetDialog.SheetItemColor.Blue                                , new ActionSheetDialog.OnSheetItemClickListener() {                            @Override                            public void onClick(int which) {                                //填写事件                            }                        })                        .addSheetItem("备注", ActionSheetDialog.SheetItemColor.Blue                                , new ActionSheetDialog.OnSheetItemClickListener() {                            @Override                            public void onClick(int which) {                                //填写事件                            }                        }).show();                break;            case R.id.btn4:                new AlertDialog(MainActivity.this)                        .builder()                        .setTitle("退出当前帐号")                        .setMsg("再连续登陆天,就可变身为QQ达人。退出QQ可能会使你现有记录归零,确定退出?")                        .setPositiveButton("确认退出", new View.OnClickListener() {                            @Override                            public void onClick(View v) {                                //填写事件                            }                        })                        .setNegativeButton("取消", new View.OnClickListener() {                            @Override                            public void onClick(View v) {                                //填写事件                            }                        }).show();                break;            case R.id.btn5:                new AlertDialog(MainActivity.this)                        .builder()                        .setTitle("错误信息")                        .setMsg("你的手机sd卡出现问题,建议删除不需要的文件,否则收不到图片和视频等打文件")                        .setPositiveButton("确定", new View.OnClickListener() {                            @Override                            public void onClick(View v) {                                //填写事件                            }                        }).show();                break;        }    }}


java代码主要是简要的说明了IOS_Dialog_Library的五种不同的实现方法及效果。可以在注释部分写点击事件。



3、运行效果图

         

运行效果图1                                   点击"消息"示意图2

         

点击"图片"效果图3                              点击"列表Item"效果图4

         

点击"退出弹窗"效果图5                           点击"错误提示窗口"图6


源码下载地址:http://download.csdn.net/detail/u012721519/9501050


Good luck!

Write by Jimmy.li











2 0