unit Android.JNI.Toast;// Java bridge class imported by hand by Brian Long (http://blong.com)interface{$IFDEF ANDROID}uses  Androidapi.JNIBridge,  Androidapi.JNI.JavaTypes,  Androidapi.JNI.GraphicsContentViewText;{$ENDIF}{$IFDEF ANDROID}type  TToastLength = (LongToast, ShortToast);  JToast = interface;  JToastClass = interface(JObjectClass)    ['{69E2D233-B9D3-4F3E-B882-474C8E1D50E9}']    { Property methods }    function _GetLENGTH_LONG: Integer; cdecl;    function _GetLENGTH_SHORT: Integer; cdecl;    { Methods }    function init(context: JContext): JToast; cdecl; overload;    function makeText(context: JContext; text: JCharSequence; duration: Integer)      : JToast; cdecl;    { Properties }    property LENGTH_LONG: Integer read _GetLENGTH_LONG;    property LENGTH_SHORT: Integer read _GetLENGTH_SHORT;  end;  [JavaSignature('android/widget/Toast')]  JToast = interface(JObject)    ['{FD81CC32-BFBC-4838-8893-9DD01DE47B00}']    { Methods }    procedure cancel; cdecl;    function getDuration: Integer; cdecl;    function getGravity: Integer; cdecl;    function getHorizontalMargin: Single; cdecl;    function getVerticalMargin: Single; cdecl;    function getView: JView; cdecl;    function getXOffset: Integer; cdecl;    function getYOffset: Integer; cdecl;    procedure setDuration(value: Integer); cdecl;    procedure setGravity(gravity, xOffset, yOffset: Integer); cdecl;    procedure setMargin(horizontalMargin, verticalMargin: Single); cdecl;    procedure setText(s: JCharSequence); cdecl;    procedure setView(view: JView); cdecl;    procedure show; cdecl;  end;  TJToast = class(TJavaGenericImport<JToastClass, JToast>)  end;procedure Toast(const Msg: string; duration: TToastLength = ShortToast);{$ENDIF}implementation{$IFDEF ANDROID}uses  FMX.Helpers.Android;procedure Toast(const Msg: string; duration: TToastLength);var  ToastLength: Integer;begin  if duration = ShortToast then    ToastLength := TJToast.JavaClass.LENGTH_SHORT  else    ToastLength := TJToast.JavaClass.LENGTH_LONG;  CallInUiThread(    procedure    begin      TJToast.JavaClass.makeText(SharedActivityContext, StrToJCharSequence(Msg),        ToastLength).show    end);end;{$ENDIF}end.
View Code


使用方法:短提示 Toast(s) 长时间提示: Toast(s,LongToast);

如图:

更多相关文章

  1. Delphi XE5 android toast
  2. 【Android】播放提示音
  3. android onSaveInstanceState的使用方法
  4. android使用自定义标题时提示“you cannot combine custom title
  5. Android(安卓)lint 检查提示汇总
  6. Android中JNI的使用方法
  7. Android(安卓)Studio 提示错误:No IDEA annotations attached to
  8. xarmain使用Forms编译android工程出现support_r19.0.1.zip支持包
  9. Android(安卓)Studio 小提示,新建Activity

随机推荐

  1. ComScore:Android(安卓)以 44% 在美国智能
  2. Android(安卓)studio启动后卡在refreshin
  3. apk反编译和重新打包
  4. MonoDroid学习笔记(一)―― 搭建MonoDroid
  5. Google+ 手機App中文介面新登場, Android
  6. Android开发学习指南,同时庆祝第二款手机
  7. Android下DLNA开发简介
  8. Android使用huffman编码进行图片压缩
  9. 【Android(安卓)学习记录】:针对Android(
  10. 如何确定Android中刚修改后的c/c++是否编