(Android)react-native解决 ToastAndroid(安卓)不消失问题
16lz
2021-01-26
本文主要是解决RN中的Toast提示按顺序执行不会提前消失的问题
解决思路是更改原生Toast的一些内容。
1、先用RN调用原生Android方法
2、新建MyUtil的类,代码如下,这是用来解决上一个Toast不消失的问题的。
package com.testtoastdemo.newToast;import android.content.Context;import android.widget.Toast;/** * Created by hhy on 2018/3/19. */public class MyUtil { private static Toast mToast; public static void showToast(Context context, int resId, int duration){ showToast(context, context.getString(resId), duration); } public static void showToast(Context context, String msg, int duration) { if (mToast == null) { mToast = Toast.makeText(context, msg, duration); } else { mToast.setText(msg); } mToast.show(); }}
3、调用该类中方法的核心代码是
MyUtil.showToast(this.getCurrentActivity(), msg, 2000);
4、最后在RN中调用newToastMethod方法
let rnToastAndroid = NativeModules.ToastByAndroid; rnToastAndroid.newToastMethod("想要提示的内容");
更多相关文章
- Android(安卓)Media Framework(3): Stagefright框架流程解读
- android右上方不显示3个点的菜单的解决方法
- Android源码分析之Framework的MediaPlayer
- Android平台实现与Apache Tomcat服务器数据交互(MySql数据库)
- Android(安卓)JNI 编译正确 但是提示程序有错误无法运行 而且还
- android ViewPager动态加载问题
- Android(安卓)开发学习手记(三):关于PullToRefresh的setOnTouchList
- Android程序退出彻底关闭进程的方法
- android 窗口背景透明方法