如何完全禁用Delphi Android应用的主页和后退按钮功能?
- 内容介绍
- 文章标签
- 相关推荐
本文共计447个文字,预计阅读时间需要2分钟。
在Delphi XE7中编写Android平板电脑应用程序时,若想移除主页和返回键,防止用户退出应用程序,可以采用以下方法:
1. 重写`OnCreate`方法,在创建窗口时禁用主页键。
2.使用`OnBackPressed`事件处理返回键,防止默认行为触发。
以下是实现这一目标的代码示例:
delphi
procedure TForm1.onCreate(savedInstanceState);begin inherited onCreate(savedInstanceState); // 禁用主页键 RequestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_main);end;procedure TForm1.onBackPressed;begin // 处理返回键,防止退出应用程序 // 可以在这里添加自定义逻辑,例如显示确认对话框 ShowMessage('按返回键将不会退出应用'); // 阻止默认的返回键行为 inherited onBackPress;end;
这段代码首先在`onCreate`方法中禁用了栏,防止显示主页键。然后在`onBackPressed`方法中,通过调用`ShowMessage`显示一个消息框来处理返回键事件,并通过调用`inherited onBackPress;`阻止默认的返回键行为。这样用户即使按下返回键,也不会退出应用程序。
我正在为Delphi XE7中的 Android平板电脑编写应用程序.我想关掉主页和后退键,这样就没有人可以离开应用程序了.我找到了很多答案,但都没有提到Delphi.我怎样才能在Delphi中实现这一目标?我应该使用哪些物品?我需要包括哪些单位?
从 documentation起Using the Android Device’s Back Button
To make your application handle when users press the Back button on
their Android device, add an event handler to your form for OnKeyUp,
and use the following code within your event handler: In Delphi:
if Key = vkHardwareBack then begin // Do whatever you want to do here Key := 0; // Set Key = 0 if you want to prevent the default action end;
本文共计447个文字,预计阅读时间需要2分钟。
在Delphi XE7中编写Android平板电脑应用程序时,若想移除主页和返回键,防止用户退出应用程序,可以采用以下方法:
1. 重写`OnCreate`方法,在创建窗口时禁用主页键。
2.使用`OnBackPressed`事件处理返回键,防止默认行为触发。
以下是实现这一目标的代码示例:
delphi
procedure TForm1.onCreate(savedInstanceState);begin inherited onCreate(savedInstanceState); // 禁用主页键 RequestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_main);end;procedure TForm1.onBackPressed;begin // 处理返回键,防止退出应用程序 // 可以在这里添加自定义逻辑,例如显示确认对话框 ShowMessage('按返回键将不会退出应用'); // 阻止默认的返回键行为 inherited onBackPress;end;
这段代码首先在`onCreate`方法中禁用了栏,防止显示主页键。然后在`onBackPressed`方法中,通过调用`ShowMessage`显示一个消息框来处理返回键事件,并通过调用`inherited onBackPress;`阻止默认的返回键行为。这样用户即使按下返回键,也不会退出应用程序。
我正在为Delphi XE7中的 Android平板电脑编写应用程序.我想关掉主页和后退键,这样就没有人可以离开应用程序了.我找到了很多答案,但都没有提到Delphi.我怎样才能在Delphi中实现这一目标?我应该使用哪些物品?我需要包括哪些单位?
从 documentation起Using the Android Device’s Back Button
To make your application handle when users press the Back button on
their Android device, add an event handler to your form for OnKeyUp,
and use the following code within your event handler: In Delphi:
if Key = vkHardwareBack then begin // Do whatever you want to do here Key := 0; // Set Key = 0 if you want to prevent the default action end;

