Android实例-消息框(XE8+小米2)
方法一支持。
方法二与方法三都是三方单元,功能相同。
方法4与方法5报错,提示平台不支持。
第三方单元一:
unit Android.JNI.Toast; // Java bridge class imported by hand by Brian Long (http://blong.com)
interface {$IFDEF ANDROID} uses
Androidapi.Helpers,
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.
第三方单元二:
{***************************************************************************}
{ }
{ 功能:Android Toast提示消息框 }
{ 名称:Androidapi.JNI.Widget.Toast.pas }
{ 版本:1.0 }
{ 环境:Win7 Sp1 64bit }
{ 工具:Delphi XE7 }
{ 日期:2014-11-23 19:45:35 }
{ 用法:TToast.Show(MessageText, isLongHint) }
{--------------------------------------------------------------------------}
{ 原版作者:ying32 }
{ QQ:396506155 }
{ MSN :ying_32@live.cn }
{ E-mail:yuanfen3287@vip.qq.com }
{ Website:http://blog.csdn.net/zyjying520/article/details/26158941 }
{ 版权所有 (C) 2013-2013 ying32.tk All Rights Reserved }
{---------------------------------------------------------------------------}
{ 修改者:tht2009 }
{ 改动:1、去掉注释掉的方法 }
{ 2、移动FMX.Helpers.Android引用声明到实现区 }
{ 3、增加Androidapi.Helpers引用 }
{ }
{***************************************************************************} unit Androidapi.JNI.Widget.Toast; interface uses
Androidapi.JNIBridge,
Androidapi.JNI.JavaTypes,
Androidapi.JNI.GraphicsContentViewText; 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; implementation uses FMX.Helpers.Android, Androidapi.Helpers; { 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, StrToJCharSequence(text), LDuration).show;
end
);
end; end.
应用单元:
unit Unit1; interface uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
FMX.Controls.Presentation, FMX.StdCtrls; type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
Button6: TButton;
Button7: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure Button7Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end; var
Form1: TForm1; implementation uses
Android.JNI.Toast, Androidapi.JNI.Widget.Toast;
{$R *.fmx}
{$R *.NmXhdpiPh.fmx ANDROID} procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage('与原来的一样哦!'); //消息提示方法一
end; procedure TForm1.Button2Click(Sender: TObject);
begin
Toast('消息提示方法二', LongToast);
end; procedure TForm1.Button3Click(Sender: TObject);
begin
Toast('消息提示方法二', ShortToast);
end; procedure TForm1.Button4Click(Sender: TObject);
begin
TToast.Show('消息提示方法3。', False);
end; procedure TForm1.Button5Click(Sender: TObject);
begin
TToast.Show('消息提示方法3。', True);
end; procedure TForm1.Button6Click(Sender: TObject);
begin
if MessageDlg('你喜欢我吗?', TMsgDlgType.mtConfirmation,
[TMsgDlgBtn.mbYes, TMsgDlgBtn.mbNo], -) = mrYes then
begin end;
end; procedure TForm1.Button7Click(Sender: TObject);
var
msresult: string;
begin
msresult := FMX.Dialogs.InputBox('询问', '你多大了?', '我 10 岁了。');
ShowMessage('你输入的是:' + msresult);
end; end.
Android实例-消息框(XE8+小米2)的更多相关文章
- Android实例-操作摄像头(XE8+小米2)
结果: 1.同样是照相,自己的程序设置为高质量时刷新慢,而小米手机的相机那真心反映快呀. 2.就算我设置为最高质量,可相片也没有小米手机的相片大.我最大是2000*1000,而小米可以做到3000*2 ...
- Android实例-手机震动(XE8+小米2)
相关资料:http://blog.csdn.net/laorenshen/article/details/41148843 结果: 1.打开Vibrate权限为True. 2.规律震动我没感觉出来,有 ...
- Android实例-LocationSensor位置传感器(XE8+小米2)
结果: 1.启动后有时会闪退,后来重新做的工程就好了.原因不明(可能与地理反码有关). 2.原文是用的GOOGLE地图显示位置,但在咱们这里好像不行,改为百度,但百度用的是HTML文件.太麻烦了,大家 ...
- Android实例-MotionSensor加速度(XE8+小米2)
结果: 1. 实例代码: unit Unit1; interface uses System.SysUtils, System.Types, System.UITypes, System.Classe ...
- Android实例-设置消息提醒(XE8+小米2)
相关资料: 1.官网实例:http://docwiki.embarcadero.com/RADStudio/XE5/en/Mobile_Tutorial:_Using_the_Notification ...
- Android实例-实现扫描二维码并生成二维码(XE8+小米5)
相关资料: 第三方资料太大没法写在博文上,请下载CSDN的程序包. 程序包下载: http://download.csdn.net/detail/zhujianqiangqq/9657186 注意事项 ...
- Android实例-调用GOOGLE的TTS实现文字转语音(XE7+小米2)(无图)
注意:在手机上必须选安装文字转语音引擎“google Text To Speech”地址:http://www.shouji56.com/soft/GoogleWenZiZhuanYuYinYinQi ...
- Android实例-调用GOOGLE的TTS实现文字转语音(XE7+小米2)(XE10.1+小米5)
相关资料: 注意:在手机上必须选安装文字转语音引擎“google Text To Speech”地址:http://www.shouji56.com/soft/GoogleWenZiZhuanYuYi ...
- 【C#】分享一个可携带附加消息的增强消息框MessageBoxEx
--------------201507160917更新--------------- 无意中发现标准消息框在Windows7是有声音的,只是在Windows server 2008(R2)无声,而我 ...
随机推荐
- hdu 4678 Mine 博弈论
这是一题简单的博弈论!! 所有的空白+边界的数字(个数为n)为一堆,容易推出其SG函数值为n%2+1: 其他所有的数字(个数为m)的SG值为m%2. 再就是用dfs将空白部分搜一下即可!(注意细节) ...
- codeforces #313 div1 B
模拟判定就可以了 判定字符串是否相等用hash来判断 QAQ 值得一提的是一开始我交的时候T了 结果我将递归的顺序调整了一下就A了 (并不知道为什么 #include<cstdio> #i ...
- win7下VS.NET中通过LinqToSQL连接oracle数据库
.NetFramework3.5提供了LinqToSQL组件,为我们访问数据库提供了方便.我用的是VS+Oracle开发工具.也想体验一下快捷方便的感觉. 1.连接Oracle数据库 在连接Oracl ...
- 数据库存储安全之(MD5+盐)加密
一般系统数据库密码加密方式: MD5后存入数据库 SHA1 Hash后存入数据库 缺点:黑客可以通过密码暴力破解获取密码信息,具体做法是将常用密码进行Hash后做成一个字典, 破解的时候,只需要查字典 ...
- 一步一步制作yaffs/yaffs2根文件系统(三)---使用glibc库构造 /lib
开发环境:Ubuntu 12.04 开发板:mini2440 256M NandFlash 64M SDRAM glibc库:点此下载 交叉编译器:arm-linux-gcc 4.4.3点此可下 ...
- messagePack编解码
首先引入javassist-3.20.0-GA.jar与msgpack-0.6.12.jar两个包,然后就可以使用. package com.ming.netty.code; import java. ...
- 测试darwin calendar 服务器
cd CalDAVTester README.txt中说的明白—— QUICKSTART Edit the serverinfo.xml file to run the test against yo ...
- centos 搭建 darwin calendar 服务器
方法一(官网方法): useradd caluser ----为日历服务器建立一个新用户,方便管理 passwd caluser -----新用户更改密码 su caluser mkdir ~/Cal ...
- 批量产生ssh2项目中hibernate带注解的pojo类的快捷方法
近几个月一直在忙于项目组的ios应用项目的开发,没有太多时间去研究web应用方面的问题了.刚好,昨天有网友问到如何批量产生hibernate带注解的pojo类的快捷方法,所谓批量就是指将当前数据库中所 ...
- Java [Leetcode 104]Maximum Depth of Binary Tree
题目描述: Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along th ...