Карта сайта Kansoftware
НОВОСТИУСЛУГИРЕШЕНИЯКОНТАКТЫ
KANSoftWare

Показать клавиатуру в приложении на Android с помощью Delphi и OpenGL

Delphi , Графика и Игры , OpenGL

Show Soft Keyboard in Android with Delphi OpenGL App (No FMX)

Problem Description:

Daniel is developing an OpenGL application using Delphi on Android without using FireMonkey (FMX). He wants to show the soft keyboard when the app gains focus, but he's struggling to achieve this. He's tried various approaches, including using ANativeActivity_showSoftInput, creating a JWindow, and modifying the AndroidManifest.template.xml, but none of these methods worked.

Confirmed Solution:

After extensive efforts, Daniel finally found a solution. Instead of using the InputMethodManager, he accessed the "TextEditorProxy" of the native activity instance created by Delphi for Android apps. Here's the working code:

CallInUIThread(
  procedure
  var
    fmx: JFMXNativeActivity;
    TextView: JFMXTextEditorProxy;
  begin
    fmx := TJFMXNativeActivity.Wrap(FApp^.activity.clazz);
    TextView := fmx.getTextEditorProxy;
    TextView.setFocusable(True);
    TextView.setFocusableInTouchMode(True);
    TextView.requestFocus;
    TextView.showSoftInput(True);
  end);

Alternative Solution:

After two days of googling, I found an alternative solution that works with Delphi XE11.1. Here's the code:

CallInUIThread(
  procedure
  var
    wnd: JWindow;
    ctx: JContext;
    ctxcls: JContextClass;
    imm: JInputMethodManager;
    immcls: JInputMethodManagerClass;
    view: JView;
    ret: Boolean;
  begin
    wnd := MainActivity.getWindow;
    view := wnd.getDecorView;
    view.setFocusable(True);
    view.setFocusableInTouchMode(True);
    ret := MainActivity.getVirtualKeyboard.showFor(View);
  end);

Conclusion:

Both solutions allow you to show the soft keyboard in a Delphi OpenGL app on Android without using FMX. The first solution uses the "TextEditorProxy" of the native activity instance, while the second solution uses the InputMethodManager with some modifications. You can choose the solution that best fits your needs.

Создано по материалам из источника по ссылке.

' Даниэль разрабатывает приложение OpenGL с помощью Delphi на Android без использования FireMonkey (FMX) и хочет показывать клавиатуру при получении фокуса, но ему не удается реализовать это.'


Комментарии и вопросы

Получайте свежие новости и обновления по Object Pascal, Delphi и Lazarus прямо в свой смартфон. Подпишитесь на наш Telegram-канал delphi_kansoftware и будьте в курсе последних тенденций в разработке под Linux, Windows, Android и iOS




Материалы статей собраны из открытых источников, владелец сайта не претендует на авторство. Там где авторство установить не удалось, материал подаётся без имени автора. В случае если Вы считаете, что Ваши права нарушены, пожалуйста, свяжитесь с владельцем сайта.


:: Главная :: OpenGL ::


реклама


©KANSoftWare (разработка программного обеспечения, создание программ, создание интерактивных сайтов), 2007
Top.Mail.Ru

Время компиляции файла: 2024-12-22 20:14:06
2025-02-05 19:04:20/0.003122091293335/0