Delphi XE5 - Textfield not visible when Virtual Keyboard is open

Hey, I habe a problem.

I created a new project with 2 textfields.
When I set the focus on my smartphone to one of them, the virtual keyboard open and is shown over the textfield.

Is there any way to "scroll up" the textfields, to have the vkeyboard below the textfields and not over it?

Here are 2 screenshots:

 [http://i.imagebanana.com/img/a55t5ciw/Screenshot_20130920150032.png] 
 [http://i.imagebanana.com/img/isi0gorw/Screenshot_20130920150037.png]
0
David
9/22/2013 8:32:29 PM
embarcadero.delphi.firemonkey 4901 articles. 4 followers. Follow

12 Replies
7969 Views

Similar Articles

[PageSpeed] 28

David Kurz wrote:

> Is there any way to "scroll up" the textfields, to have the vkeyboard below the textfields and not over it?

I have a TToolbar on my main form with Align set to alTop, and a TTabControl below it with Align set to alClient. When
the virtualkeyboard is shown/hidden the OnVirtualKeyboardShown/OnVirtualKeyboardHidden events fire, so I have the
following code to make the TTabControl slide up/down, that may be of use to you:

{code}
function TfrmMain.FocusedControl: TControl;
begin
  Result := nil;
  if Assigned(Focused) and (Focused.GetObject is TControl) then
    Result := TControl(Focused.GetObject);
end;

function TfrmMain.GetFocusedControlOffset(KeyboardRect: TRect): Single;
var
  Control: TControl;
  ControlPos: TPointF;
  KeyboardTop: Single;
begin
  Result := 0;
  KeyboardTop := Height - (KeyboardRect.Bottom - KeyboardRect.Top) - 66; // At least, should be. 66 is the height of
the keyboard "done" bar
  Control := FocusedControl;
  if Assigned(Control) then
  begin
    ControlPos := Control.LocalToAbsolute(PointF(0, 0));
    Result := KeyboardTop - ControlPos.Y + Control.Height + 2;
    if Result >= 0 then
      Result := 0;
  end;
end;

procedure TfrmMain.FormVirtualKeyboardHidden(Sender: TObject; KeyboardVisible: Boolean; const Bounds: TRect);
begin
  tabMain.AnimateFloat('Position.Y', FSavedY, 0.1);
  tabMain.Align := TAlignLayout.alClient;
end;

procedure TfrmMain.FormVirtualKeyboardShown(Sender: TObject; KeyboardVisible: Boolean; const Bounds: TRect);
begin
  tabMain.Align := TAlignLayout.alNone;
  FSavedY := tabMain.Position.Y;
  tabMain.AnimateFloat('Position.Y', FSavedY + GetFocusedControlOffset(Bounds), 0.1);
end;
{code} 

-- 
Dave Nottage [TeamB]
1
Dave
9/22/2013 9:26:52 PM
-
0
David
9/22/2013 10:00:35 PM
Thank you, solved my problem.
0
David
9/22/2013 10:00:48 PM
Hello,

how I can know if the keyboard is active or not in Delphi xe5 for android? I need to know that to control the event back button devices.

I thank you.

att.

Wagner.

> {quote:title=Dave Nottage wrote:}{quote}
> David Kurz wrote:
> 
> > Is there any way to "scroll up" the textfields, to have the vkeyboard below the textfields and not over it?
> 
> I have a TToolbar on my main form with Align set to alTop, and a TTabControl below it with Align set to alClient. When
> the virtualkeyboard is shown/hidden the OnVirtualKeyboardShown/OnVirtualKeyboardHidden events fire, so I have the
> following code to make the TTabControl slide up/down, that may be of use to you:
> 
> {code}
> function TfrmMain.FocusedControl: TControl;
> begin
>   Result := nil;
>   if Assigned(Focused) and (Focused.GetObject is TControl) then
>     Result := TControl(Focused.GetObject);
> end;
> 
> function TfrmMain.GetFocusedControlOffset(KeyboardRect: TRect): Single;
> var
>   Control: TControl;
>   ControlPos: TPointF;
>   KeyboardTop: Single;
> begin
>   Result := 0;
>   KeyboardTop := Height - (KeyboardRect.Bottom - KeyboardRect.Top) - 66; // At least, should be. 66 is the height of
> the keyboard "done" bar
>   Control := FocusedControl;
>   if Assigned(Control) then
>   begin
>     ControlPos := Control.LocalToAbsolute(PointF(0, 0));
>     Result := KeyboardTop - ControlPos.Y + Control.Height + 2;
>     if Result >= 0 then
>       Result := 0;
>   end;
> end;
> 
> procedure TfrmMain.FormVirtualKeyboardHidden(Sender: TObject; KeyboardVisible: Boolean; const Bounds: TRect);
> begin
>   tabMain.AnimateFloat('Position.Y', FSavedY, 0.1);
>   tabMain.Align := TAlignLayout.alClient;
> end;
> 
> procedure TfrmMain.FormVirtualKeyboardShown(Sender: TObject; KeyboardVisible: Boolean; const Bounds: TRect);
> begin
>   tabMain.Align := TAlignLayout.alNone;
>   FSavedY := tabMain.Position.Y;
>   tabMain.AnimateFloat('Position.Y', FSavedY + GetFocusedControlOffset(Bounds), 0.1);
> end;
> {code} 
> 
> -- 
> Dave Nottage [TeamB]
-1
Wagner
9/27/2013 2:59:29 PM
Wagner Alexandre wrote:

> how I can know if the keyboard is active or not in Delphi xe5 for android?

The same way as in my example.

-- 
Dave Nottage [TeamB]
0
Dave
9/30/2013 12:19:37 AM
Is the solution presented here the only way to accomplish this?  I was expecting there to be a built-in handler or property of some sort that should scroll the form (or allow it to be scrolled) when the keyboard is shown.  Seems like this would be an extremely popular problem at least half the time (half the page is covered by the keyboard).  Hoping that there's a more robust/simple solution to this, especially since every form in every app written will have this problem.


> {quote:title=David Kurz wrote:}{quote}
> Hey, I habe a problem.
> 
> I created a new project with 2 textfields.
> When I set the focus on my smartphone to one of them, the virtual keyboard open and is shown over the textfield.
> 
> Is there any way to "scroll up" the textfields, to have the vkeyboard below the textfields and not over it?
> 
> Here are 2 screenshots:
> 
>  [http://i.imagebanana.com/img/a55t5ciw/Screenshot_20130920150032.png] 
>  [http://i.imagebanana.com/img/isi0gorw/Screenshot_20130920150037.png]
0
Eric
10/11/2013 3:14:31 AM
Thank you very much for good question and answer. 
I'm totaly disappointed about this. I think every single developer must have this problem and it seems that only working solution, is to do it in code. (Not in design) That sad. I have some experience with developing apps in java - eclipse. In that framework is this "scrolling" done automatically. 
And there is also possibility to make "floating buttons" above virtual keyboard. e.g. to have [Save] [Cancel] buttons allways above shown keyboard. That is pretty handy, but in current version of XE5 unfortunatelly not possible. :(
0
juraj
11/2/2013 12:08:05 PM
> {quote:title=David Kurz wrote:}{quote}
> Is there any way to "scroll up" the textfields, to have the vkeyboard below the textfields and not over it?

I was playing with this the other day and came up with the following which is simpler than Dave's code. You'll need to add FMX.Ani to the uses clause and I'd recommend extracting DoneBarHeight to a separate unit.

{code}
const DoneBarHeight = 66;

procedure TCalculatorForm.FormVirtualKeyboardHidden(Sender: TObject;
  KeyboardVisible: Boolean; const Bounds: TRect);
begin
  if not KeyboardVisible then
    AnimateFloat('Padding.Top', 0, 0.1);
end;

procedure TCalculatorForm.FormVirtualKeyboardShown(Sender: TObject;
  KeyboardVisible: Boolean; const Bounds: TRect);
var O: TFMXObject;
begin
  if Assigned(Focused) and (Focused.GetObject is TControl) then
    if TControl(Focused).AbsoluteRect.Bottom - Padding.Top >= (Bounds.Top - DoneBarHeight) then
    begin
      //If switching between controls, the KeyboardHidden animation will run first
      //and we'll see the form scroll up and then down.
      //Calling StopPropertyAnimation jumps the first animation to it's final value - same problem
      //Instead we need to search for the other animation and call StopAtCurrent.
      for O in Children do
        if (O is TFloatAnimation) and (TFloatAnimation(O).PropertyName = 'Padding.Top') then
          TFloatAnimation(O).StopAtCurrent;
      AnimateFloat('Padding.Top',
        Bounds.Top - DoneBarHeight - TControl(Focused).AbsoluteRect.Bottom + Padding.Top, 0.1)
    end
    else
  else
    AnimateFloat('Padding.Top', 0, 0.1);
end;{code}

--
FireMonkey users guide http://bit.ly/10abRZX
MonkeyStyler FireMonkey style designer http://bit.ly/PzxKyI
Embarcadero MVP
1
Mike
11/6/2013 10:02:23 PM
Mike Sutton wrote:

> I was playing with this the other day and came up with the following which is simpler than Dave's code

Except that it moves *everything* up. Refer to my article:

http://delphi.radsoft.com.au/2013/10/moving-controls-into-view-when-the-virtual-keyboard-is-shown/

Refer to the second and third animations, especially the one with the memo.

-- 
Dave Nottage [TeamB]
Find tips and code samples at Delphi Worlds: 
http://delphi.radsoft.com.au/blog
0
Dave
11/6/2013 10:23:40 PM
Thanks a lot for this solution and sample. 
Move all shifting work to the separate component is very good idea, code is reusable. Maybe some automatic assigment to the event OnChange in TMemo will be nice, but nevertheless it is perfect solution.
0
juraj
11/10/2013 1:35:03 PM
> {quote:title=Dave Nottage wrote:}{quote}
> Except that it moves *everything* up. Refer to my article:
> 
> http://delphi.radsoft.com.au/2013/10/moving-controls-into-view-when-the-virtual-keyboard-is-shown/

It doesn't have to. Pop the controls on (say) a TLayout and adjust the Padding.Top there instead (i.e. call Layout1.AnimateXXX).

--
FireMonkey users guide http://bit.ly/10abRZX
MonkeyStyler FireMonkey style designer http://bit.ly/PzxKyI
Embarcadero MVP
0
Mike
11/10/2013 2:02:10 PM
Mike Sutton wrote:

> It doesn't have to. Pop the controls on (say) a TLayout and adjust the Padding.Top there instead (i.e. call
> Layout1.AnimateXXX).

You could do that, yes. My other point about the TMemo is that when it moves, the bottom of the control appears above
the VK, when you might not have wanted it to, eg you "click" in the middle of the text because that's where you want to
edit. The method I use ensures the text you want to edit is just above the VK. That said, your code could be modified
to suit.

-- 
Dave Nottage [TeamB]
Find tips and code samples at Delphi Worlds: 
http://delphi.radsoft.com.au/blog
0
Dave
11/10/2013 8:00:29 PM
Reply:

Web resources about - Delphi XE5 - Textfield not visible when Virtual Keyboard is open - embarcadero.delphi.firemonkey

smartNote for iPad on the iTunes App Store
Read reviews, get customer ratings, see screenshots, and learn more about smartNote on the App Store. Download smartNote and enjoy it on your ...

ActionScript - Wikipedia, the free encyclopedia
ActionScript is an object-oriented language originally developed by Macromedia Inc. (now owned by Adobe Systems ). It is a dialect of ECMAScript ...

Contact Us
Thank you for choosing to contact Adelaide ACA. Please use the form below and one of our expert automotive dealers will be in touch.

Contact Us
Thank you for choosing to contact Infinite Eye. Please use the form below and one of our website experts will be in touch.

Fields Of Meaning/Becoming
When we discuss the engaging aspects of Recombinant Poetic works, we need to seek a conceptthat can help us understand the operation of how meaning ...

Contact the Mackay Branch
Cherish Life Queensland all life is special cherish it - not abortion. Formerly Right to Life Queensland. Cherish Life Queensland is a non-denominational, ...

Fillip / Advertising Information
Fillip, a contemporary art magazine from Vancouver, Canada

Form builder example - 2h.com
Skip to main content 2h.com All the tests you need Main menu Home IQ tests Personality tests EQ tests Articles You are here Home Navigation Form ...

Send Email From Spotlight With SpotMail Jailbreak Tweak
... Search page. Once download and installed, users can email from Spotlight simply by entering an email address in the Spotlight Search textfield, ...

OS X Lion: About FileVault 2
OS X Lion provides a new version of FileVault: FileVault 2 uses full disk, XTS-AES 128 encryption to help keep your data secure. With FileVault ...

Resources last updated: 1/3/2016 11:10:40 PM