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怎么分页
  • 热门搜索
    qq被盗了怎么办 牛排怎么煎才嫩 文号的括号怎么打 菲诗小铺的东西怎么样 李云龙怎么死的 建筑图纸怎么看 高考用英语怎么说 美素力奶粉怎么样 bathroom怎么读 我的世界怎么做附魔书