首页 > 代码库 > Toast

Toast

以下摘自http://blong.com/Articles/DelphiXE6AndroidActivityResult/ActivityResult.htm

unit Androidapi.JNI.Toast;

//Java bridge class imported by hand by Brian Long (http://blong.com)

interface

uses
  Androidapi.JNIBridge,
  Androidapi.JNI.JavaTypes,
  Androidapi.JNI.GraphicsContentViewText;

type
  TToastLength (LongToast, ShortToast);

  JToast interface;

  JToastClass interface(JObjectClass)
  [‘{69E2D233-B9D3-4F3E-B882-474C8E1D50E9}‘]
    {Property methods}
    function _GetLENGTH_LONGIntegercdecl;
    function _GetLENGTH_SHORTIntegercdecl;
    {Methods}
    function init(context: JContext): JToastcdecloverload;
    function makeText(context: JContext; text: JCharSequence; durationInteger): JToastcdecl;
    {Properties}
    property LENGTH_LONGInteger read _GetLENGTH_LONG;
    property LENGTH_SHORTInteger read _GetLENGTH_SHORT;
  end;

  [JavaSignature(‘android/widget/Toast‘)]
  JToast interface(JObject)
  [‘{FD81CC32-BFBC-4838-8893-9DD01DE47B00}‘]
    {Methods}
    procedure cancelcdecl;
    function getDurationIntegercdecl;
    function getGravityIntegercdecl;
    function getHorizontalMarginSinglecdecl;
    function getVerticalMarginSinglecdecl;
    function getView: JViewcdecl;
    function getXOffsetIntegercdecl;
    function getYOffsetIntegercdecl;
    procedure setDuration(valueInteger)cdecl;
    procedure setGravity(gravity, xOffset, yOffsetInteger)cdecl;
    procedure setMargin(horizontalMargin, verticalMarginSingle)cdecl;
    procedure setText(s: JCharSequence)cdecl;
    procedure setView(view: JView)cdecl;
    procedure showcdecl;
  end;
  TJToast class(TJavaGenericImport<JToastClass, JToast>end;

procedure Toast(const Msgstring; Duration: TToastLength = ShortToast);

implementation

uses
  FMX.Helpers.Android,
  Androidapi.Helpers;

procedure Toast(const Msgstring; Duration: TToastLength);
var
  ToastLengthInteger;
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;

end.

Toast