<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的使用方法。
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的五种不同的实现方法及效果。可以在注释部分写点击事件。
运行效果图1 点击"消息"示意图2
点击"图片"效果图3 点击"列表Item"效果图4
点击"退出弹窗"效果图5 点击"错误提示窗口"图6
源码下载地址:http://xiazai.jb51.net/201701/yuanma/AndroidshowDialog(jb51.net).rar
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。