Toast.makeText中参数的含义

 时间:2026-02-16 15:07:30

1、Toast继承自Object,

(即java.lang.Object

        ↳android.widget.Toast)

2、官方API上写着:public static Toast makeText (Context context, int resId, int duration)

context =The context to use. Usually your Application or Activity object.

(使用上下文。通常您的应用程序或Activity对象。)

resId=The resource id of the string resource to use. Can be formatted text.(使用string资源的id去调用,或者可以使用格式化的文本。)

duration=How long to display the message. Either LENGTH_SHORT or LENGTH_LONG(显示信息时间的长短。可以是length_short或length_long)

3、或者也可以这么理解:

第一个参数:当前的上下文环境。可用getApplicationContext()或者getContext()或this

第二个参数:要显示的字符串。也可是R.string中字符串ID

第三个参数:显示的时间长短。Toast默认的有两个LENGTH_LONG(长3.5秒)和LENGTH_SHORT(短2秒),也可以使用毫秒如1000ms(不建议)

  • 在WORD里编辑为什么两页纸张大小不一样
  • word如何删除空白页
  • word怎么删除空白页
  • word怎么删除展开折叠按钮
  • Word怎么分页
  • 热门搜索
    crayons怎么读 乘号怎么打 排骨怎么做 微信号怎么申请 蜜蜂蛰了怎么消肿止痒 微信打不开怎么回事 breakfast怎么读 花甲怎么炒 怎么数胎动 六角恐龙怎么养