0

介绍

请注意,下面链接中提供的解决方案并没有帮助我解决我的问题:

如何检测Android应用程序何时进入后台并返回前台

你好堆栈溢出社区

我正在尝试创建简单的 Android 应用程序,该应用程序允许用户选择文本和大写或小写,以及删除多余空格的功能。我的应用程序只有三个对象,即两个 ofTButton和一个TMemo. 我遇到了TMemo和 虚拟键盘的问题。每当弹出虚拟键盘时,它都会显示在TMemo. OnVirtualKeyboardHidden我已经设法通过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 TAlignLayoutins 没有恢复到alClient.

如果有人可以帮助我解决这个TMemo虚拟键盘问题,我将不胜感激。

先感谢您!

4

1 回答 1

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>

另外,如果您想“如何知道应用程序何时进入后台?”,您可以尝试添加此功能:

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

当应用程序进入后台时调用此函数。还有更多类似的函数,如 onStart()、onResume、onRestart()、onStop() 和 onDestroy()。他们的工作正如他们的名字所暗示的那样。

于 2015-11-28T22:09:59.047 回答