如何知道应用程序何时进入后台

时间:2015-11-28 21:44:29

标签: android firemonkey delphi-xe8 android-virtual-keyboard

简介

请注意,以下链接中提供的解决方案无法帮助我解决问题:

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

Hallo Stack Overflow社区

我正在尝试创建简单的Android应用程序,允许用户选择文本以及大写或小写,以及删除多余空格的功能。我的应用只有三个对象,即两个TButton和一个TMemo。我遇到了TMemo和虚拟键盘的问题。只要弹出虚拟键盘,它就会显示在TMemo的底部。我设法通过使用OnVirtualKeyboardHidden的{​​{1}}和OnVirtualKeybaordShown事件处理程序来解决此问题。我是这样做的:

TForm

问题

所以这是我的问题:每当显示虚拟键盘并切换到另一个应用程序并切换回来时,虚拟键盘都会隐藏,但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; TMemo无法恢复到{{1 }}

如果有人可以帮我解决这个TAlignLayout和虚拟键盘问题,我会非常感激。

提前谢谢!

1 个答案:

答案 0 :(得分:0)

您可以在活动的布局文件中使用ScrollView。通过这种方式,您可以向上和向下滚动以查看虚拟键盘隐藏的内容。

以下是一个例子:

<?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>

另外,如果您想要&#34;如何知道应用程序何时进入背景?&#34;,您可以尝试添加此功能:

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

当app进入后台时调用此函数。 还有更多类似的函数,如onStart(),onResume,onRestart(),onStop()和onDestroy()。 他们就像他们的名字一样工作。

相关问题