Android 如何";“俯卧撑”;显示软键BORD时的屏幕
我在我的LibGDX安卓应用程序中有一个表,在一些文本字段(一行)下面,还有一个按钮(提交)。 我的问题是,当文本字段聚焦(点击它)并出现软键盘时,如何向上滑动表格、文本字段和按钮? 换句话说,如何使软键盘不覆盖我的其他对象。 此解决方案可能与此问题有关:Android 如何";“俯卧撑”;显示软键BORD时的屏幕,android,libgdx,soft-keyboard,Android,Libgdx,Soft Keyboard,我在我的LibGDX安卓应用程序中有一个表,在一些文本字段(一行)下面,还有一个按钮(提交)。 我的问题是,当文本字段聚焦(点击它)并出现软键盘时,如何向上滑动表格、文本字段和按钮? 换句话说,如何使软键盘不覆盖我的其他对象。 此解决方案可能与此问题有关: 非常感谢。在您的中,将android:windowSoftInputMode设置为adjustPan,我找到了一个解决问题的方法,它正在工作,但我认为不太干净。 因此,我的设想是: 一个容器表,包含一个滚动窗格(另一个表),在此滚动表下有
非常感谢。在您的
中,将android:windowSoftInputMode
设置为adjustPan
,我找到了一个解决问题的方法,它正在工作,但我认为不太干净。
因此,我的设想是:
- 一个容器表,包含一个滚动窗格(另一个表),在此滚动表下有两个文本字段,它们下面有一个提交按钮
- 容器表设置为填充父对象(全屏)
- 文本字段和按钮与容器表的底部对齐
问题是,当OnscreenKeybord可见时,它覆盖了底部对象(文本字段和按钮)和滚动表的一部分
我的解决方案/解决方法是:
keyboard = new OnscreenKeyboard() {
@Override
public void show(boolean visible) {
Gdx.input.setOnscreenKeyboardVisible(visible);
// Hmmmm...
container.invalidate();
if (visible) {
// TODO get OsK height somehow!!!
container.padBottom(310);
} else {
container.padBottom(0);
}
}
};
textFld1.setOnscreenKeyboard(keyboard);
textFld2.setOnscreenKeyboard(keyboard);
在Submit按钮的InputListener上(触地时),我有一个清理功能,如:
textFld1.setText("");
textFld2.setText("");
stage.unfocus(textFld1);
stage.unfocus(textFld2);
keyboard.show(false);
这样,当软键盘显示时,容器表将被填充,并在按下提交按钮后恢复;此外,软键盘是隐藏的
现在,此解决方案存在两个问题:
- 我还没有找到一种方法来获得软键盘的高度;正如您在示例代码中所看到的,我为up padding选择了一个任意值,因此在我的模拟器上看起来不错
- 如果按下emulator中的硬按钮Back或ESC,软键盘将隐藏,但表的向上填充仍将存在;我没有找到如何确定软键盘是否可见的方法
如果有人为我的问题找到了另一个解决方案,请发布它
谢谢。我也在全力解决这个问题,但我想我找到了一个非常好的解决方案
理论上的解决方案:
当键盘弹出时,它会调整屏幕大小,从而调用libgdx的resize回调
优势:
- 不需要与键盘可见性检测相关的逻辑
- 不需要得到键盘的高度
- 处理libgdx的screen类的resize回调中的所有内容
- 易于实现(我认为)
缺点
- 应用程序不能再全屏显示;状态栏会显示和显示其他内容
如何做:
创建一个main_layout.xml
文件(…YourLibGdxThing\android\res\layout\main_layout.xml
)以包含以下xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/main_frame_layout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
</LinearLayout>
将style.xml
(…YourLibGdxThing\android\res\values\styles.xml
)中的android:windowFullScreen
属性更改为false;XML在style.XML中应该是这样的:
<resources>
<style name="GdxTheme" parent="android:Theme">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:colorBackgroundCacheHint">@null</item>
<item name="android:windowAnimationStyle">@android:style/Animation</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowFullscreen">false</item> <!-- IMPORTANT -->
</style>
</resources>
谢谢!我希望这会有帮助 感谢您的快速回答,我尝试了您的解决方案,但它似乎不适用于libGDX。结果是一样的,当单击文本字段时,底部对象被软键盘覆盖。我从未尝试过它,而是尝试将Gdx.gl.glViewport
从软键高度设置为屏幕高度和正常宽度。我不确定软键是否使用相同的视口,但如果不是,这应该是您正在寻找的。您好,我试图了解您指的是什么,但我失败了:)您能给我一个提示吗?我希望这对您有所帮助:。“BlackOrders”应该是你的软键盘。有趣的阅读,它肯定会对我以后的这个应用程序有所帮助,但我没有找到任何关于这个具体问题的帮助。无论如何,谢谢你,正如上面所说的,那里的信息稍后会对我有所帮助。你知道如何正确订购吗?如果你调整游戏屏幕的大小,以适应软键和键盘,键盘将填充黑键。至少我希望如此。可能是键盘属于游戏,因此它显示在调整大小的windos中。看看这个:。我认为这个解决方案也有帮助。它可以工作,但它确实可以调整整个屏幕的大小,使其更小。
<resources>
<style name="GdxTheme" parent="android:Theme">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:colorBackgroundCacheHint">@null</item>
<item name="android:windowAnimationStyle">@android:style/Animation</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowFullscreen">false</item> <!-- IMPORTANT -->
</style>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="my.project.reverse.domain.thing"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="22" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/GdxTheme" >
<activity
android:name="my.project.reverse.domain.thing.AndroidLauncher"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize" <!-- IMPORTANT -->
android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>