An open API service indexing awesome lists of open source software.

https://github.com/bingoogolapple/bgaalertcontroller-android

仿写从 iOS8 开始支持的 UIAlertController
https://github.com/bingoogolapple/bgaalertcontroller-android

Last synced: about 1 month ago
JSON representation

仿写从 iOS8 开始支持的 UIAlertController

Awesome Lists containing this project

README

          

# :running:BGAAlertController-Android:running:

[![License](https://img.shields.io/badge/license-Apache%202-green.svg)](https://www.apache.org/licenses/LICENSE-2.0)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/cn.bingoogolapple/bga-alertcontroller/badge.svg)](https://maven-badges.herokuapp.com/maven-central/cn.bingoogolapple/bga-alertcontroller)

工作以来公司UI设计师出的Android效果图都是iOS风格的UIAlertView和UIActionSheet,新项目还是用原来那一套,不想重复造轮子,所以仿写了从iOS8开始支持的UIAlertController,统一UIAlertView和UIActionSheet的用法

### 效果图

![Demo](http://7xk9dj.com1.z0.glb.clouddn.com/alertcontroller/screenshots/alertcontroller3.gif)

### 基本使用

#### 1.添加Gradle依赖

``` groovy
dependencies {
compile 'cn.bingoogolapple:bga-alertcontroller:latestVersion@aar'
}
```

#### 2.在java代码中使用BGAAlertController

``` Java
public void showAlertView(View v) {
BGAAlertController alertController = new BGAAlertController(this, "我是标题", "我是很长很长很长很长很长很长很长很长很长很长很长很长的消息", BGAAlertController.AlertControllerStyle.Alert);
// 不管添加顺序怎样,AlertActionStyle.Cancel始终是在最底部的,AlertActionStyle.Default和AlertActionStyle.Destructive按添加的先后顺序显示
alertController.addAction(new BGAAlertAction("取消", BGAAlertAction.AlertActionStyle.Cancel, new BGAAlertAction.Delegate() {
@Override
public void onClick() {
showToast("点击了取消");
}
}));
alertController.addAction(new BGAAlertAction("其他1", BGAAlertAction.AlertActionStyle.Default, new BGAAlertAction.Delegate() {
@Override
public void onClick() {
showToast("点击了其他1");
}
}));
alertController.addAction(new BGAAlertAction("其他2", BGAAlertAction.AlertActionStyle.Default, new BGAAlertAction.Delegate() {
@Override
public void onClick() {
showToast("点击了其他2");
}
}));
alertController.addAction(new BGAAlertAction("确定", BGAAlertAction.AlertActionStyle.Destructive, new BGAAlertAction.Delegate() {
@Override
public void onClick() {
showToast("点击了确定");
}
}));
alertController.show();
}

public void showActionSheet(View v) {
BGAAlertController alertController = new BGAAlertController(this, "我是标题", "我是很长很长很长很长很长很长很长很长很长很长很长很长的消息", BGAAlertController.AlertControllerStyle.ActionSheet);
// 不管添加顺序怎样,AlertActionStyle.Cancel始终是在最底部的,AlertActionStyle.Default和AlertActionStyle.Destructive按添加的先后顺序显示
alertController.addAction(new BGAAlertAction("取消", BGAAlertAction.AlertActionStyle.Cancel, new BGAAlertAction.Delegate() {
@Override
public void onClick() {
showToast("点击了取消");
}
}));
alertController.addAction(new BGAAlertAction("其他1", BGAAlertAction.AlertActionStyle.Default, new BGAAlertAction.Delegate() {
@Override
public void onClick() {
showToast("点击了其他1");
}
}));
alertController.addAction(new BGAAlertAction("其他2", BGAAlertAction.AlertActionStyle.Default, new BGAAlertAction.Delegate() {
@Override
public void onClick() {
showToast("点击了其他2");
}
}));
alertController.addAction(new BGAAlertAction("确定", BGAAlertAction.AlertActionStyle.Destructive, new BGAAlertAction.Delegate() {
@Override
public void onClick() {
showToast("点击了确定");
}
}));
alertController.show();
}
```

### 高级用法

> 1.如果您不满意默认的颜色,在自己项目的colors.xml中定义以下相应地颜色即可(不用全部定义,对不满意的值重新定义即可)

``` xml

#01000000
#F9F9F9

#007AFF
#FF3B30
#EBEBEB

#000000
#000000

#4d4d4d
#8f8f8f

```

> 2.如果您不满意默认的间距和字体大小,在自己项目的dimens.xml中定义以下相应的dimen(不用全部定义,对不满意的值重新定义即可)

``` xml

10dp
10dp
1dp
18sp
14sp
14sp

18sp
14sp

```

> 3.如果您不满意默认动画时间,在自己项目的integers.xml中定义以下相应的integer
``` xml

300

```

## 作者联系方式

| 个人主页 | 邮箱 |
| ------------- | ------------ |
| bingoogolapple.cn | bingoogolapple@gmail.com |

| 个人微信号 | 微信群 | 公众号 |
| ------------ | ------------ | ------------ |
| 个人微信号 | 微信群 | 公众号 |

| 个人 QQ 号 | QQ 群 |
| ------------ | ------------ |
| 个人 QQ 号 | QQ 群 |

## 打赏支持作者

如果您觉得 BGA 系列开源库或工具软件帮您节省了大量的开发时间,可以扫描下方的二维码打赏支持。您的支持将鼓励我继续创作,打赏后还可以加我微信免费开通一年 [上帝小助手浏览器扩展/插件开发平台](https://github.com/bingoogolapple/bga-god-assistant-config) 的会员服务

| 微信 | QQ | 支付宝 |
| ------------- | ------------- | ------------- |
| 微信 | QQ | 支付宝 |

## 作者项目推荐

* 欢迎您使用我开发的第一个独立开发软件产品 [上帝小助手浏览器扩展/插件开发平台](https://github.com/bingoogolapple/bga-god-assistant-config)

## License

```
Copyright 2015 bingoogolapple

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
```