修正 XE5 Android 键盘三个问题
说明:XE5 在 Android 平台上存在这一些键盘操作的问题,目前发现有下列几种:
- 按键盘上的隐藏键后,无法按上一页(需要修改 XE5 源码「FMX.VirtualKeyboard.Android.pas」)。
- 按键盘上的隐藏键后,无法触发 OnVirtualKeyboardHidden 事件。
- 关闭键盘后,再点一次无法显示键盘(大部份机子都有这个问题,实测 Nexus 7 II 没有这个问题)。
适用:Delphi XE5 update 2
参考:此修正方法是参考「完美解决 XE5 安卓下 虚拟键盘 隐藏没有事件的 BUG。」在此感谢。
目前发现的键盘问题,需要修改 XE5 源码「FMX.VirtualKeyboard.Android.pas」才能修正,改好的档案已经放在上面源码 zip 里,改动内容如下({+++>}内为增加的部份{<+++}):
FMX.VirtualKeyboard.Android.pas
{+++>}
function ObtainKeyboardRect: TRect;
var
ContentRect, TotalRect: JRect;
begin
ContentRect := TJRect.Create;
TotalRect := TJRect.Create;
MainActivity.getWindow.getDecorView.getWindowVisibleDisplayFrame(ContentRect);
MainActivity.getWindow.getDecorView.getDrawingRect(TotalRect);
Result := TRectF.Create(ConvertPixelToPoint(TPointF.Create(TotalRect.left, TotalRect.top + ContentRect.height)),
ConvertPixelToPoint(TPointF.Create(TotalRect.right, TotalRect.bottom))).Truncate;
end;
{<+++}
function TVirtualKeyboardAndroid.GetVirtualKeyBoardState: TVirtualKeyBoardState;
begin
if FError then
Result := [vksError]
else
Result := [];
if IsAutoShow then
Result := Result + [vksAutoShow];
if not FError then
begin
{+++>}
// 这里只解决: 按键盘上的隐藏后, 无法再按上一页的问题 (按上一页后, 才会执行这里).
if FState = vkbsVisible then
if ObtainKeyboardRect.Height < then
SetState(TVirtualKeyboardAndroid.TvkbState.vkbsHidden);
{<+++}
if FState = vkbsVisible then
Result := Result + [vksVisible];
end;
end;
Main.pas
//------------------------------------------------------------------------------
// 2014.04. by 龟山阿卍 QQ -
// http://www.cnblogs.com/onechen/ -
// -
// 需修改 -
// FMX.VirtualKeyboard.Android.pas -
//------------------------------------------------------------------------------ unit Main; interface uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, FMX.Platform,
FMX.VirtualKeyboard.Android,
FMX.VirtualKeyboard, FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Edit,
FMX.StdCtrls, FMX.Layouts, FMX.Memo; type
TForm1 = class(TForm)
ToolBar1: TToolBar;
Label1: TLabel;
VirtualKeyboardTimer: TTimer;
Memo1: TMemo;
Edit1: TEdit;
procedure FormVirtualKeyboardHidden(Sender: TObject;
KeyboardVisible: Boolean; const Bounds: TRect);
procedure FormVirtualKeyboardShown(Sender: TObject;
KeyboardVisible: Boolean; const Bounds: TRect);
procedure VirtualKeyboardTimerTimer(Sender: TObject);
procedure Edit1Click(Sender: TObject);
private
{ private declarations }
public
{ Public declarations }
end; var
Form1: TForm1; implementation {$R *.fmx} // 显示键盘
function ShowVirtualKeyboard(const AControl: TFmxObject): Boolean;
var Service1: IFMXVirtualKeyboardService;
begin
if (ObtainKeyboardRect.Height < ) and
TPlatformServices.Current.SupportsPlatformService(IFMXVirtualKeyboardService, IInterface(Service1)) then
Result := Service1.ShowVirtualKeyboard(AControl)
else Result := False;
end; procedure TForm1.FormVirtualKeyboardHidden(Sender: TObject;
KeyboardVisible: Boolean; const Bounds: TRect);
begin
Edit1.Text := 'Keyboard hidden!';
Memo1.Text := Format('W: %d H: %d', [Bounds.Width, Bounds.Height]); VirtualKeyboardTimer.Enabled := False; // 关闭检查键盘高度
end; procedure TForm1.FormVirtualKeyboardShown(Sender: TObject;
KeyboardVisible: Boolean; const Bounds: TRect);
begin
Edit1.Text := 'Keyboard shown!';
Memo1.Text := Format('W: %d H: %d', [Bounds.Width, Bounds.Height]); VirtualKeyboardTimer.Enabled := True; // 开启检查键盘高度
end; procedure TForm1.VirtualKeyboardTimerTimer(Sender: TObject);
var R: TRect;
begin
// 检查键盘高度 < 代表键盘关闭.
R := ObtainKeyboardRect;
if R.Height < then
Self.OnVirtualKeyboardHidden(Sender, False, R);
end; procedure TForm1.Edit1Click(Sender: TObject);
begin
// 在 TEdit 或 TMemo 需要用到键盘的控件, 加入下行, 才能确保关闭键盘后, 再点一次可以显示键盘.
ShowVirtualKeyboard(TFmxObject(Sender));
end; end.
「键盘上的隐藏键」是指下图所示位置:

修正 XE5 Android 键盘三个问题的更多相关文章
- xe5 android 手机上使用sqlite [转]
在android手机上怎样使用sqlite数据库,这里用Navigator实现 增删改查. 1.新建firemonkey mobile application 2.选择blank applicatio ...
- 免Root停用“Android键盘(AOSP)”
一.效果:隐藏手机状态栏输入法选择图标: 二.手段:使用ADB免root 停用系统默认Android键盘(AOSP),这里参考了大神的方法,在此表示感谢: 三.实现过程: 上图 下面就是按照大神的方法 ...
- android键盘输入读取
android键盘输入读取 监控android键盘输入方式有两种,一种在java层实现,重写onKeyDown和onKeyUp方法.另一种是在jni层实现,监控/dev/input/event0键盘 ...
- xe5 android tts(Text To Speech)
xe5 android tts(Text To Speech) TTS是Text To Speech的缩写,即“从文本到语音”,是人机对话的一部分,让机器能够说话. 以下代码实现xe5 开发的文本转 ...
- XE5 ANDROID通过webservice访问操作MSSQL数据库
上接XE5 ANDROID平台 调用 webservice 一.服务端 在ro里添加函数(在impl上添加阿东connection,adoquery,dataprovider) function TN ...
- Android动画 三种动画
Android可以使用三种动画 Frame Animation-帧动画 ,就像GIF图片,通过一系列Drawable依次显示来模拟动画的效果 Tween Animation-补间动画,给出两个关键帧, ...
- delphi xe5 android 服务端和手机端的源码下载
xe5 android的服务端和手机客户端的源代码下载地址 http://files.cnblogs.com/nywh2008/AndroidTest.rar
- 【转】Android LCD(三):Samsung LCD接口篇
关键词:android LCD控制器 Framebuffer PWM 平台信息:内核:linux2.6/linux3.0系统:android/android4.0 平台:samsung exynos ...
- 【转】android camera(三):camera V4L2 FIMC
关键词:android camera CMM 模组 camera参数 CAMIF V4L2 平台信息:内核:linux系统:android 平台:S5PV310(samsung exynos ...
随机推荐
- java 堆栈分析3
很多方式,比如jconsole.jvisualvm,或者jstack -as 这样的形式, 都可以看到实时的java堆栈的变化: eden suvirried0 suvirried1 old perg ...
- 开发者最常用的 8 款 Sublime Text 3 插件
转载于:http://www.itxuexiwang.com/a/liunxjishu/2016/0228/177.html?1456925631Sublime Text作为一个尽为人知的代码编辑器, ...
- Ubuntu 12.04下GAMIT10.40安装说明
转载于:http://www.itxuexiwang.com/a/liunxjishu/2016/0225/164.html?1456481297 Ubuntu 12.04下GAMIT10.40安装步 ...
- Oracle建表脚本记录
--删除 drop table dianfei; --创建表 create table dianfei ( uon ) not null, mmonth ) not null, ddf ,) not ...
- 大叔也说Xamarin~Android篇~监听返回键,单击返回某个webView,双击退出
回到目录 这个操作在原生android里是很容易实现的,在xamarin里也不难,在activity里有方法OnKeyDown,我们只需要重写一下就可以了,然后通过webView重新加载到要返回的页面 ...
- atitit.Servlet2.5 Servlet 3.0 新特性 jsp2.0 jsp2.1 jsp2.2新特性
atitit.Servlet2.5 Servlet 3.0 新特性 jsp2.0 jsp2.1 jsp2.2新特性 1.1. Servlet和JSP规范版本对应关系:1 1.2. Servlet2 ...
- spring容器对bean生命周期的管理三中方式
spring容器对bean的生命周期管理主要在两个时间点:bean的初始化完成(包括属性值被完全注入),bean的销毁(程序结束,或者引用结束)方式一:使用springXML配置中的init-meth ...
- dropzone的使用方法
http://www.renfei.org/blog/dropzone-js-introduction.html dropzone.js 是一个开源的 JavaScript 库,提供 AJAX 异步上 ...
- Topology and Geometry in OpenCascade-Edge
Topology and Geometry in OpenCascade-Edge eryar@163.com 摘要Abstract:本文简要介绍了几何造型中的边界表示法(BRep),并结合程序说明O ...
- ionic+nodejs开发遇到的跨域和post请求数据问题
最近学习ionic+nodejs开发混合app中遇到了一些问题,在此总结一下. 开发环境搭建 项目地址 https://github.com/ytudt/nodejsApp 代码和问题都会在之后的学习 ...