• Delphi XE里面 SharedActivityContext 提示错误


    使用歪果仁的unit

    //--------------------

    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,
    Androidapi.Helpers;//加上,否则SharedActivityContext提示错误,

    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.

    //-------------------

    在使用的页面:


    uses
    Android.JNI.Toast,

    procedure TForm2.FormKeyUp(Sender: TObject; var Key: Word; var KeyChar: Char;
    Shift: TShiftState);
    begin
    if (Key = vkHardwareBack) or (Key = vkEscape) then
    begin
    if IsFirstBack then
    begin
    IsFirstBack := False;
    Key := 0;
    Timer1.Enabled := True;
    Toast('再按一次退出',ShortToast);
    // Toast('再按一次退出',ShortToast);
    end
    else
    begin
    end;
    end;
    end;

    窗体上(TForm2)Onkeyup-->FormKeyUp

  • 相关阅读:
    测试Leader应该做哪些事
    软件测试基础理论详解
    测试用例设计方法--场景分析法详解
    测试用例设计方法--因果图法、判断表法详解
    测试用例设计方法--正交试验法详解
    jira创建仪表盘以及对应的数据用二维表显示
    如何对PyCharm进行设置
    selenium+python自动化测试环境安装
    卸载loadrunner
    通过抓包工具(fiddler)获取手机app/微信的网络信息
  • 原文地址:https://www.cnblogs.com/yuyang2100/p/4777814.html
Copyright © 2020-2023  润新知