delphi android Toast
发布时间:2020-12-15 10:00:11 所属栏目:大数据 来源:网络整理
导读:曾经这个单元被人说成是骗子,剽窃别人的,虽然后来那个人道歉了,但我还是想说一句,当初为我写这个单元我从晚上10点熬到了零晨1点多,那时候第一次接触delphi for android 看了好多遍系统定义的那些单元,了解了是怎么将java代码翻译过来,然后自己一点点的摸索,?
曾经这个单元被人说成是骗子,剽窃别人的,虽然后来那个人道歉了,但我还是想说一句,当初为我写这个单元我从晚上10点熬到了零晨1点多,那时候第一次接触delphi for android 看了好多遍系统定义的那些单元,了解了是怎么将java代码翻译过来,然后自己一点点的摸索,? 从java? eclipse中一行行的将java的函数复制过来然后修改,起初遇到了不少问题, 不明白的地方非常的,但没有地方问,我只能硬着头皮去调试,还是用的真机调式,而且真机usb口坏了,用ftp传的,想想都苦啊,最后在不断的努力下终于完成了,然后才去睡觉 {***************************************************************************} { } { 功能:Android Toast提示消息框 } { 名称:Androidapi.JNI.Widget.Toast.pas } { 版本:1.0 } { 环境:Win7 Sp1 32bit } { 工具:Delphi XE5 } { 日期:2013-10-30 01:26:35 } { 作者:ying32 } { QQ :396506155 } { MSN :ying_32@live.cn } { E-mail:yuanfen3287@vip.qq.com } { Website: } { 版权所有 (C) 2013-2013 ying32.tk All Rights Reserved } { } {---------------------------------------------------------------------------} { } { 备注:显示Toast提示框 } { 用法:ToastMessageShow(MessageText,duration) } { } { } {***************************************************************************} unit Androidapi.JNI.Widget.Toast; interface uses Androidapi.JNIBridge,Androidapi.JNI.JavaTypes,Androidapi.JNI.GraphicsContentViewText,FMX.Helpers.Android; type JToast = interface;//android.widget.Toast JToastClass = interface(JObjectClass) ['{CF455B66-683D-41F9-B386-0C49E42D4F92}'] {Property Methods} function _GetLENGTH_LONG: Integer; function _GetLENGTH_SHORT : Integer; {Methods} // public Toast (Context context) function init(context: JContext): JToast; cdecl; // public static Toast makeText (Context context,int resId,int duration) function makeText(context: JContext; resId: Integer; duration: Integer): JToast;cdecl;overload; // public static Toast makeText (Context context,CharSequence text,int duration) function makeText(context: JContext; text: JCharSequence; duration: Integer): JToast;cdecl;overload; {Properties} property LENGTH_LONG: Integer read _GetLENGTH_LONG; property LENGTH_SHORT: Integer read _GetLENGTH_SHORT; end; [JavaSignature('android/widget/Toast')] JToast = interface(JObject) ['{4A284317-000C-4048-8674-C475F505CFAF}'] {Methods} // public void cancel () procedure cancel;cdecl; // public int getDuration () function getDuration: Integer; cdecl; // public int getGravity () function getGravity: Integer; cdecl; // public float getHorizontalMargin () function getHorizontalMargin: Single; cdecl; // public float getVerticalMargin () function getVerticalMargin: Single; cdecl; // public View getView () function getView: JView; cdecl; // public int getXOffset () function getXOffset: Integer; cdecl; // public int getYOffset () function getYOffset: Integer; cdecl; // public void setDuration (int duration) procedure setDuration(duration: Integer); cdecl; // public void setGravity (int gravity,int xOffset,int yOffset) procedure setGravity(gravity,xOffset,yOffset: Integer);cdecl; // public void setMargin (float horizontalMargin,float verticalMargin) procedure setMargin(horizontalMargin,verticalMargin: Single);cdecl; // public void setText (int resId) procedure setText(resId: Integer);cdecl;overload; // public void setText (CharSequence s) procedure setText(s: JCharSequence);cdecl;overload; // public void setView (View view) procedure setView(view: JView);cdecl; // public void show () procedure show;cdecl; end; TJToast = class(TJavaGenericImport<JToastClass,JToast>) end; { TToast } TToast = class public class procedure Show(const text: string; LongHint: Boolean = False); end; // 显示消息 // procedure ToastMessageShow(const text: string; LongHint: Boolean = False); implementation //procedure ToastMessageShow(const text: string; LongHint: Boolean); //var // LDuration: Integer; //begin // CallInUIThread // ( // procedure // begin // case LongHint of // True : LDuration := TJToast.JavaClass.LENGTH_LONG; // False : LDuration := TJToast.JavaClass.LENGTH_SHORT; // end; // TJToast.JavaClass.makeText(SharedActivityContext,StrToJCharSequence(text),LDuration).show; // end // ); //end; { TToast } class procedure TToast.Show(const text: string; LongHint: Boolean); var LDuration: Integer; begin CallInUIThread ( procedure begin case LongHint of True : LDuration := TJToast.JavaClass.LENGTH_LONG; False : LDuration := TJToast.JavaClass.LENGTH_SHORT; end; TJToast.JavaClass.makeText(SharedActivityContext,LDuration).show; end ); end; end. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |