0

Introduction

Note, the solution provided in the link below did not help me solve my problem:

How to detect when an Android app goes to the background and come back to the foreground

Hallo Stack Overflow Community

I am trying to create simple Android app that allows a user to select text and upper or lower case it, along with a function to remove extra spaces. My app has only three objects, namely two of TButton and one of TMemo. I have encountered a problem with the TMemoand the virtual keyboard. Whenever the virtual keyboard pops up, it displays over the bottom of the TMemo. I have managed to solve this problem by working with the OnVirtualKeyboardHiddenand OnVirtualKeybaordShown event handlers of the TForm. Here’s how I did it:

procedure TfrmEditor.FormVirtualKeyboardHidden(Sender: TObject;
  KeyboardVisible: Boolean; const Bounds: TRect);
begin
  memInput.Align := memInput.Align.alClient;
end;

procedure TfrmEditor.FormVirtualKeyboardShown(Sender: TObject;
  KeyboardVisible: Boolean; const Bounds: TRect);
begin
  if memInput.Align <> memInput.Align.alTop then
  begin
    memInput.Align := memInput.Align.alTop;
    memInput.Height := memInput.Height - Bounds.Height;
  end;
end;

Problem

So here’s my problem: whenever the virtual keyboard is shown and I switch to another app and switch back, the virtual keyboard is hidden but the TMemo TAlignLayout ins’t restored back to alClient.

If anyone can help me with this TMemo and virtual keyboard problem I would really appreciate it.

Thank you in advance!

Community
  • 1
  • 1

1 Answers1

0

You can use ScrollView in your activity's layout file. By this, you can scroll up and down to view the things hidden by the virtual keybooard.

Here's an example:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:fillViewport="true">

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:weightSum="1">

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="75dp"
                android:text="Welcome!"
                android:id="@+id/textView"
                android:gravity="center"
                android:textColor="#33b5e5"
                android:textSize="35sp"/>

        </LinearLayout>  
    </LinearLayout>
</ScrollView>

Also, if you you want to "How to know when app goes in backgrond?", you can try adding this function:

public void onPause()
{
    super.oPause();
}

This function is called when app goes in the background. There are more similar functions like onStart(),onResume,onRestart(),onStop() and onDestroy(). They work as their name suggests.

Rohan Sharma
  • 69
  • 3
  • 13