|
12 | 12 | ### 创建一个ActionSheet并显示
|
13 | 13 |
|
14 | 14 | ```java
|
15 |
| -new ActionSheet.Builder(this, getSupportFragmentManager()) |
| 15 | +ActionSheet.createBuilder(this, getSupportFragmentManager()) |
16 | 16 | .setCancelButtonTitle("Cancel")
|
17 | 17 | .setOtherButtonTitles("Item1", "Item2", "Item3", "Item4")
|
| 18 | + .setCancelableOnTouchOutside(true) |
18 | 19 | .setListener(this).show();
|
19 | 20 | ```
|
20 | 21 |
|
| 22 | +### 方法说明 |
| 23 | + |
| 24 | +* `setCancelButtonTitle()` 设置取消按钮的标题 |
| 25 | +* `setOtherButtonTitles()` 设置条目,String[] |
| 26 | +* `setCancelableOnTouchOutside()` 设置点击空白处关闭 |
| 27 | +* `setListener()` 设置事件监听器 |
| 28 | +* `show()` 返回`ActionSheet`对象,可以调用`ActionSheet`对象的`dismiss()`方法手动关闭 |
| 29 | + |
21 | 30 | ### 事件监听
|
22 | 31 |
|
23 | 32 | 实现`ActionSheetListener`接口
|
| 33 | +* `onOtherButtonClick()` 点击某个条目,`index`是条目的下标 |
| 34 | +* `onCancel` 取消事件,点击取消按钮,或者点击空白处(`setCancelableOnTouchOutside(true)`) |
| 35 | +* `onDismiss()` 关闭事件 |
24 | 36 |
|
25 | 37 | ```java
|
26 |
| - @Override |
27 |
| - public void onCancelButtonClick(ActionSheet actionSheet) { |
28 |
| - Toast.makeText(getApplicationContext(), "click cancel", 0).show(); |
29 |
| - } |
30 |
| - |
31 |
| - @Override |
| 38 | + @Override |
32 | 39 | public void onOtherButtonClick(ActionSheet actionSheet, int index) {
|
33 | 40 | Toast.makeText(getApplicationContext(), "click item index = " + index,
|
34 | 41 | 0).show();
|
35 | 42 | }
|
| 43 | + |
| 44 | + @Override |
| 45 | + public void onCancel(ActionSheet actionSheet) { |
| 46 | + Toast.makeText(getApplicationContext(), "cancel", 0).show(); |
| 47 | + } |
| 48 | + |
| 49 | + @Override |
| 50 | + public void onDismiss(ActionSheet actionSheet) { |
| 51 | + Toast.makeText(getApplicationContext(), "dismissed", 0).show(); |
| 52 | + } |
36 | 53 | ```
|
37 | 54 |
|
38 | 55 | ### 样式
|
|
0 commit comments