我正在尝试让我的Xamarin.Forms应用程序使用Android的沉浸式模式,因为我使用的是一个小屏幕的设备,所以软键和导航栏抢走了我宝贵的屏幕空间。
由于我使用的设备具有硬件键盘,所以我想隐藏软键盘。目前,我通过安装“空输入法”键盘解决了这个问题。但是,键盘仍然存在,所以每次请求将焦点放在Entry元素上时,键盘都会被“显示”。这会导致应用程序退出沉浸式模式。当我在forms应用程序中显示Alert时也是如此。
理想情况下,我希望我的应用程序始终处于沉浸式模式,至少在请求将焦点放在输入上时(软键盘根本不“显示”,或者当键盘“显示”时不禁用沉浸式模式)。对于警报,我希望应用程序在隐藏警报时重新进入沉浸式模式。目前我用自定义的DisplayAlert方法扩展了Page类来解决这个问题,这个方法在DisplayAlert任务完成后切换到沉浸式模式。
我做了一些研究,找到了以下文章:Immersive mode while using keyboard用户显然解决了这个问题,所以可能会有解决方案?
https://forums.xamarin.com/discussion/33034/prevent-entry-soft-keyboard-from-showing-on-android但此解决方案不适用于Entry元素,因此我希望避免为元素编写自定义渲染器。
有没有人以前遇到过类似的问题,并设法解决了?
发布于 2018-12-06 06:53:52
这不是最好的解决方案,但对我来说无疑是最简单的。
试试这个:
final Handler forceImmersive = new Handler();
Runnable runnable = new Runnable() {
@Override
public void run() {
// Enables regular immersive mode.
// For "lean back" mode, remove SYSTEM_UI_FLAG_IMMERSIVE.
// Or for "sticky immersive," replace it with SYSTEM_UI_FLAG_IMMERSIVE_STICKY
View decorView = getWindow().getDecorView();
decorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
// Set the content to appear under the system bars so that the
// content doesn't resize when the system bars hide and show.
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
// Hide the nav bar and status bar
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN);
forceImmersive.postDelayed(this, 1000);
}
};
forceImmersive.postDelayed(runnable, 1000);
https://stackoverflow.com/questions/51962983
复制相似问题