本文主要是解决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("想要提示的内容");

更多相关文章

  1. Android(安卓)Media Framework(3): Stagefright框架流程解读
  2. android右上方不显示3个点的菜单的解决方法
  3. Android源码分析之Framework的MediaPlayer
  4. Android平台实现与Apache Tomcat服务器数据交互(MySql数据库)
  5. Android(安卓)JNI 编译正确 但是提示程序有错误无法运行 而且还
  6. android ViewPager动态加载问题
  7. Android(安卓)开发学习手记(三):关于PullToRefresh的setOnTouchList
  8. Android程序退出彻底关闭进程的方法
  9. android 窗口背景透明方法

随机推荐

  1. Android(安卓)5.0 parseSdkContent faile
  2. Android(安卓)中常用代码片段
  3. android dumpsys
  4. Android学习笔记001_布局01
  5. android dumpsys
  6. android画布_Android画布
  7. Failed to find an AVD compatible with
  8. Android(安卓)的设计模式---观察者模式
  9. 在Android(安卓)studio中用网格布局做计
  10. android全景图