tencent cloud

ActionSheet

PDF
聚焦模式
字号
最后更新时间: 2025-08-28 16:01:22
说明:
SDK 中会有一些展示 ActionSheet 的场景,如小程序中调用 wx.showActionSheet。Superapp 可以通过重写 AbsMiniUiProxy.showActionSheet 接口来实现自定义风格的 ActionSheet。
ActionSheetInfo: 包括标题、选项、事件监听等 ActionSheet 基本信息,开发者可以根据这些信息创建 ActionSheet。
/**
* 通用 ActionSheet 展示接口
* @param context 上下文
* @param actionSheetInfo ActionSheet 信息
* @return true 表示使用自定义 ActionSheet,false 表示使用 SDK 默认 ActionSheet
*/
boolean showActionSheet(Activity context, ActionSheetInfo actionSheetInfo);
示例代码
@Override
public boolean showActionSheet(Activity context, ActionSheetInfo actionSheetInfo) {
ActionSheet actionSheet = ActionSheet.create(context);

// 设置标题
if (actionSheetInfo.getTitle() != null) {
actionSheet.setMainTitle(actionSheetInfo.getTitle());
}

// 设置是否可取消
actionSheet.setCancelable(actionSheetInfo.isCancelable());

// 添加items
if (actionSheetInfo.getItems() != null) {
for (ActionSheetItem item : actionSheetInfo.getItems()) {
if (item.getTextColor() != null) {
actionSheet.addButton(item.getText(), ActionSheet.CUSTOM_TEXT_COLOR_BTN,
String.format("#%08X", item.getTextColor()));
} else {
actionSheet.addButton(item.getText(), ActionSheet.GRAY_STYLE_BTN);
}
}
}

// 设置取消按钮文本
if (actionSheetInfo.getCancelText() != null) {
actionSheet.addCancelButton(actionSheetInfo.getCancelText());
}

// 设置点击监听器
if (actionSheetInfo.getItemClickListener() != null) {
actionSheet.setOnButtonClickListener(new ActionSheet.OnButtonClickListener() {
@Override
public void onClick(View clickedView, int which) {
actionSheetInfo.getItemClickListener().onClick(which);
actionSheet.dismiss();
}
});
}

// 设置取消监听器
if (actionSheetInfo.getCancelListener() != null) {
actionSheet.setOnDismissListener(new ActionSheet.OnDismissListener() {
@Override
public void onDismiss() {
actionSheetInfo.getCancelListener().onCancel(null);
}
});
}

if (!context.isFinishing() && !actionSheet.isShowing()) {
actionSheet.show();
}
return true;
}


帮助和支持

本页内容是否解决了您的问题?

填写满意度调查问卷,共创更好文档体验。

文档反馈