uniapp自定义弹窗组件|仿微信android/ios弹窗效果

uni-app自定义弹窗模板uniPop组件|uniapp仿微信弹窗|msg信息框|alert对话框|loading提示框

uniPop内置多种动画效果、可供选择类型ios/android、可以自定义弹窗样式/自定义多按钮及事件/弹窗显示位置、自动关闭秒数、遮罩层透明度及点击遮罩是否关闭

如上图:H5/小程序/App三端效果兼容性一致。(后续大图均展示App端)

如何引用

uniPop.vue弹窗组件两种引入方式:

  • 在main.js里引入全局组件

import uniPop from './components/uniPop/uniPop.vue'

Vue.component('uni-pop', uniPop) 

  • 在相应页面引入组件
<template>
    <view class="container">
        ...
        
        <!-- 弹窗模板 -->
        <uni-pop ref="uniPop"></uni-pop>
    </view>
</template>

<script>
    import uniPop from './components/uniPop/uniPop.vue'
    export default {
        data() {
            return {
                ...
            }
        },
        components:{
            uniPop
        },
        ...
    }
</script>

msg信息框效果

  

this.$refs.uniPop.show({
    content: 'msg消息提示框(5s后窗口关闭)',
    shade: true,
    shadeClose: false,
    time: 5,
    anim: 'fadeIn',
})

toast弱提示信息 - 支持success / info / error / loading四种图标

  

this.$refs.uniPop.show({
    skin: 'toast',
    content: 'loading',
    icon: 'loading', //success | info | error | loading
    shade: false,
    time: 3
})

uniPop自定义弹窗模板组件

/**
  * @tpl        uni-app自定义弹窗组件 - uniPop.vue
  * @author     andy by 2019-09-20
  * @about      Q:282310962  wx:xy190310
  */

<template>
    <view v-if="opts.isVisible" class="uniPop" :class="opts.isCloseCls">
        <view class="unipop__ui_panel">
            <view v-if="opts.shade" class="unipop__ui_mask" @tap="shadeTaped"></view>
            <view class="unipop__ui_main">
                <view class="unipop__ui_child" :style="opts.style">
                    <!-- 标题 -->
                    <view v-if="opts.title" class="unipop__ui_tit">{{opts.title}}</view>
                    <!-- 内容 -->
                    <view v-if="opts.content" class="unipop__ui_cnt" :style="opts.contentStyle">
                        {{opts.content}}
                    </view>
                    <view v-if="opts.btns" class="unipop__ui_btns">
                        <text v-for="(item,index) in opts.btns" :key="index" class="btn" :style="item.style" @tap="btnTaped(item)">{{item.text}}</text>
                    </view>
                </view>
                <!-- xclose -->
                <view v-if="opts.xclose" class="unipop__xclose" @tap="close"></view>
            </view>
        </view>
    </view>
</template>
data() {
    return {
        defaultOptions: {
            isVisible: false,       //是否显示弹窗
            
            title: '',              //标题
            content: '',            //内容
            contentStyle: '',       //内容样式
            style: null,            //自定义弹窗样式
            skin: '',               //弹窗风格
            icon: '',               //弹窗图标
            xclose: false,          //自定义关闭按钮
            
            shade: true,            //遮罩层
            shadeClose: true,       //点击遮罩关闭
            opacity: '',            //遮罩透明度
            time: 0,                //自动关闭秒数
            end: null,              //销毁弹窗回调函数
            
            anim: 'scaleIn',        //弹窗动画  scaleIn(默认) | fadeIn | shake | top | right | bottom | left
            position: '',           //弹窗位置  top | right | bottom | left
            
            btns: null,             //弹窗按钮
        },
        opts: {},
        timer: null
    }
},

好了,uniApp自定义组件弹窗介绍就到这里,希望能喜欢??~~

◆ 最后附上uniapp自定义导航栏/tabbar

uniapp自定义导航栏:https://blog.csdn.net/yanxinyun1990/article/details/100919657

uniapp自定义tabbar:https://blog.csdn.net/yanxinyun1990/article/details/101219095

 

  • 0
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
您好,要实现Android仿微信弹窗,可以使用PopupWindow和Dialog两种方法: 1.使用PopupWindow PopupWindow可以在指定的View下面或上面显示一个弹窗,使用起来比较灵活,可以自定义View,支持动画效果。具体实现步骤如下: (1)创建popupwindow.xml布局文件,定义弹窗的样式和布局。 (2)在Activity中创建PopupWindow对象,并设置显示的内容、大小、位置等属性。可以使用showAsDropDown()方法指定弹窗显示在哪个View下面,也可以使用showAtLocation()方法指定弹窗显示的位置。 (3)设置PopupWindow的动画效果,可以使用setAnimationStyle()方法。 具体代码实现可以参考以下示例: ``` //创建PopupWindow对象 PopupWindow popupWindow = new PopupWindow(context); //设置弹窗的布局文件 View contentView = LayoutInflater.from(context).inflate(R.layout.popupwindow, null); popupWindow.setContentView(contentView); //设置弹窗的宽度和高度 popupWindow.setWidth(ViewGroup.LayoutParams.MATCH_PARENT); popupWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT); //设置弹窗的背景 popupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); //设置弹窗的动画效果 popupWindow.setAnimationStyle(R.style.PopupWindowAnimation); //显示弹窗 popupWindow.showAsDropDown(anchorView); ``` 2.使用Dialog Dialog可以创建一个模态对话,可以自定义View,支持动画效果。具体实现步骤如下: (1)创建dialog.xml布局文件,定义对话的样式和布局。 (2)在Activity中创建Dialog对象,并设置显示的内容、大小、位置等属性。可以使用setContentView()方法指定对话显示的内容,也可以使用setCancelable()方法设置对话是否可以取消。 (3)设置Dialog的动画效果,可以使用getWindow().setWindowAnimations()方法。 具体代码实现可以参考以下示例: ``` //创建Dialog对象 Dialog dialog = new Dialog(context, R.style.DialogStyle); //设置对话的布局文件 View contentView = LayoutInflater.from(context).inflate(R.layout.dialog, null); dialog.setContentView(contentView); //设置对话的宽度和高度 WindowManager.LayoutParams layoutParams = dialog.getWindow().getAttributes(); layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT; layoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT; dialog.getWindow().setAttributes(layoutParams); //设置对话的背景 dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); //设置对话的动画效果 dialog.getWindow().setWindowAnimations(R.style.DialogAnimation); //显示对话 dialog.show(); ``` 希望以上解释能够帮助您实现Android仿微信弹窗

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

xiaoyan_2018

你的鼓励将是我持续作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值