Android Web 视图中隐藏在键盘下方的文本框

发布于 2024-11-28 23:44:31 字数 285 浏览 0 评论 0原文

我创建了一个简单的 iPhone/Android 应用程序,包含一个普通的 Web 视图。这个网络视图调用我的网站。

在我的网站上有几种输入类型=文本或文本区域的表单。当它们位于页面底部时,我遇到了问题!

1)在我的iPhone应用程序中,键盘会自动出现并将文本框推到手机屏幕的可见区域。所以没什么可做的。

2)但在我的 Android 应用程序中,文本框将保留在同一位置,并最终被我的键盘隐藏。因此用户唯一的选择就是输入“blind”。

我该如何解决这个问题?还有其他人遇到这个问题吗?

I have created a simple iPhone/Android app, containing a normal webview. This webview calls my website.

On my website there are several forms with input type=text or textarea. I have a problem with those when they are at the bottom of the page!

1) In my iPhone app, the keyboard will automatically appear and push the textbox to the visible area of the phone screen. So there is nothing to do.

2) But in my Android app the textbox will stay at the same place and is eventually hidden by my keyboard. So the only option users have is to type "blind".

How can I fix this? Did anyone else meet this problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

隔纱相望 2024-12-05 23:44:31

这就是我解决问题的方法。正如 Venky 所说,您必须添加

android:windowSoftInputMode="adjustResize"

到 AndroidManifest.xml 文件中的标记。但就我们而言,这还不够。确保您也对视图、网络视图等执行此操作。然后我们终于让它发挥作用了。

This is how I solved the problem. As Venky said, you have to add

android:windowSoftInputMode="adjustResize"

to your tag in the AndroidManifest.xml file. But in our case, it wasn't enough. Make sure you do this as well with your views, webviews etc. Then we finally made it work.

ら栖息 2024-12-05 23:44:31

我快疯了,没有任何效果 android:windowSoftInputMode="adjustResize" 可能有帮助,但请确保您的应用程序不是全屏显示。

删除我的应用程序的全屏解决了使用软键盘调整布局大小的问题。

<item name="android:windowFullscreen">false</item>

I was getting crazy nothing works android:windowSoftInputMode="adjustResize" may help but be sure to have your app not in full screen.

Removing full screen for my app solved the problem with the layout resize with softkeyboard.

<item name="android:windowFullscreen">false</item>
南薇 2024-12-05 23:44:31

对于全屏模式下的活动, android:windowSoftInputMode="adjustResize" 将不起作用。

https://developer.android.com/reference/android/view /WindowManager.LayoutParams.html#FLAG_FULLSCREEN

全屏窗口将忽略窗口的 softInputMode 字段的 SOFT_INPUT_ADJUST_RESIZE 值;窗口将保持全屏并且不会调整大小。

我在活动中使用以下方法通过设置底部填充来调整布局大小:


    public void adjustResizeOnGlobalLayout(@IdRes final int viewGroupId, final WebView webView) {
        final View decorView = getWindow().getDecorView();
        final ViewGroup viewGroup = (ViewGroup) findViewById(viewGroupId);

        decorView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            public void onGlobalLayout() {
                DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
                Rect rect = new Rect();
                decorView.getWindowVisibleDisplayFrame(rect);
                int paddingBottom = displayMetrics.heightPixels - rect.bottom;

                if (viewGroup.getPaddingBottom() != paddingBottom) {
                    // showing/hiding the soft keyboard
                    viewGroup.setPadding(viewGroup.getPaddingLeft(), viewGroup.getPaddingTop(), viewGroup.getPaddingRight(), paddingBottom);
                } else {
                    // soft keyboard shown/hidden and padding changed
                    if (paddingBottom != 0) {
                        // soft keyboard shown, scroll active element into view in case it is blocked by the soft keyboard
                        webView.evaluateJavascript("if (document.activeElement) { document.activeElement.scrollIntoView({behavior: \"smooth\", block: \"center\", inline: \"nearest\"}); }", null);
                    }
                }
            }
        });
    }

For activities in full screen mode, android:windowSoftInputMode="adjustResize" will not work.

https://developer.android.com/reference/android/view/WindowManager.LayoutParams.html#FLAG_FULLSCREEN

A fullscreen window will ignore a value of SOFT_INPUT_ADJUST_RESIZE for the window's softInputMode field; the window will stay fullscreen and will not resize.

I use the following method in the activity to resize the layout by setting a bottom padding:


    public void adjustResizeOnGlobalLayout(@IdRes final int viewGroupId, final WebView webView) {
        final View decorView = getWindow().getDecorView();
        final ViewGroup viewGroup = (ViewGroup) findViewById(viewGroupId);

        decorView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            public void onGlobalLayout() {
                DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
                Rect rect = new Rect();
                decorView.getWindowVisibleDisplayFrame(rect);
                int paddingBottom = displayMetrics.heightPixels - rect.bottom;

                if (viewGroup.getPaddingBottom() != paddingBottom) {
                    // showing/hiding the soft keyboard
                    viewGroup.setPadding(viewGroup.getPaddingLeft(), viewGroup.getPaddingTop(), viewGroup.getPaddingRight(), paddingBottom);
                } else {
                    // soft keyboard shown/hidden and padding changed
                    if (paddingBottom != 0) {
                        // soft keyboard shown, scroll active element into view in case it is blocked by the soft keyboard
                        webView.evaluateJavascript("if (document.activeElement) { document.activeElement.scrollIntoView({behavior: \"smooth\", block: \"center\", inline: \"nearest\"}); }", null);
                    }
                }
            }
        });
    }
壹場煙雨 2024-12-05 23:44:31

这可行:

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

This would work:

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

勿挽旧人 2024-12-05 23:44:31

在解决这个问题时我学到了一些东西——
1.主题样式不应包含Fullscreen True
2.添加 android:windowSoftInputMode="adjustResize"
3. 删除 android:scrollbars="none" 是任何..
干杯!

Few things I learnt while solving this issue ---
1. Theme style should not contain Fullscreen True
2. Add android:windowSoftInputMode="adjustResize"
3. Remove android:scrollbars="none" is any.. .
Cheers!

中性美 2024-12-05 23:44:31

除了建议答案之外,其他方法都无法工作

android:windowSoftInputMode="adjustResize"

请注意,当您处于沉浸式模式时,

Beware that apart from the suggest answers

android:windowSoftInputMode="adjustResize"

Is not working when you are in immersive mode

美煞众生 2024-12-05 23:44:31

就我而言,成功是通过以下方式实现的:

  1. 将以下内容添加到清单、webview 和片段:

    android:windowSoftInputMode="adjustResize"
    
  2. 使用非全屏主题,如下所示:

    <样式名称=“AppTheme”parent=“android:Theme.Black.NoTitleBar”>
        <项目名称=“android:windowNoTitle”>true
        <项目名称=“android:windowActionBar”>假
        <项目名称=“android:windowFullscreen”>假
    
    
  3. 不使用 WebView 上的 ScrollView。

In my case the succes achieved by:

  1. Adding below to manifest, webview and fragment:

    android:windowSoftInputMode="adjustResize"
    
  2. Using NON FullScreen Theme such as below:

    <style name="AppTheme" parent="android:Theme.Black.NoTitleBar">
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowActionBar">false</item>
        <item name="android:windowFullscreen">false</item>
    </style>
    
  3. NOT using ScrollView over WebView.
梦里人 2024-12-05 23:44:31

是的,在使用 Webview 时遇到了同样的问题,我的问题是在模态上提交的输入。文本字段没有“聚焦”在键盘上方。
解决方案是延迟函数调用。希望有人觉得这有用。

   $("body").on("click", ".jstree-search-input", function () {  

    setTimeout(function(){ 
        androidScroll(); 
    }, 500);
    });

正如你所看到的,它用于 jstree 输入...

   function androidScroll() {
    // Webview focus call (pushes the modal over keyboard)
        $('.control-sidebar-open ').scrollTop($('.control-sidebar-open ')[0].scrollHeight);

}

Yeah, had the same problem working with Webview, mine was with input filed on modal. Textfield didn't "focus" above the keyboard.
The solution was to delay the function call. Hope someone finds this usefull.

   $("body").on("click", ".jstree-search-input", function () {  

    setTimeout(function(){ 
        androidScroll(); 
    }, 500);
    });

As you can see it's used for jstree input...

   function androidScroll() {
    // Webview focus call (pushes the modal over keyboard)
        $('.control-sidebar-open ').scrollTop($('.control-sidebar-open ')[0].scrollHeight);

}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文