热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Android:如何防止软键盘将视图向上推?-Android:HowdoIpreventthesoftkeyboardfrompushingmyviewup?

Ihaveaverticalslidingdraweratthebottomofmyapp.Whenthesoftkeyboardopens,itpushesth

I have a vertical sliding drawer at the bottom of my app. When the soft keyboard opens, it pushes the tab for the drawer up, so it sits atop the keyboard. I actually want it to remain at the bottom of the screen, becoming hidden when the keyboard is shown.

我的应用程序底部有一个垂直滑动抽屉,当软键盘打开时,它会按tab键打开抽屉,所以它就放在键盘上。实际上,我希望它保持在屏幕底部,在显示键盘时隐藏起来。

Anyone else run into this issue? Know how to fix it?

还有人遇到这个问题吗?知道怎么修复吗?

21 个解决方案

#1


447  

You can simply switch your activity's windowSoftInputMode flag to "adjustPan". Check the official documentation for more info.

您可以简单地将您的活动的windowSoftInputMode标志切换到“调整”。更多信息请查看官方文档。

 

#2


122  

None of the answers worked for me, but this did the trick:

所有的答案对我都不起作用,但这一点却起了作用:

android:windowSoftInputMode="adjustNothing"

#3


61  

In my case, the reason the buttons got pushed up was because the view above them was a ScrollView, and it got collapsed with the buttons pushed up above the keyboard no matter what value of android:windowSoftInputMode I was setting.

在我的例子中,按钮被推上去的原因是因为上面的视图是一个ScrollView,不管我设置的是什么android:windowSoftInputMode,按钮被推到键盘上方就会被折叠起来。

I was able to avoid my bottom row of buttons getting pushed up by the soft keyboard by setting android:isScrollCOntainer="false" on the ScrollView that sits above the buttons.

通过设置位于按钮上方的ScrollView上的android:isScrollCOntainer="false",我可以避免我的下一行按钮被软键盘推高。

#4


50  

You can try to add this attribute dynamically, by putting the following code in the onCreate method of your activity:

您可以尝试动态添加此属性,方法是将以下代码放在活动的onCreate方法中:

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

This worked for me, rather that:

这对我起了作用,而不是:

android:windowSoftInputMode="adjustPan"

didnt.

没有。

#5


28  

These answers here didn't help me. So I tried this:

这些答案对我没有帮助。所以我试着:

android:windowSoftInputMode="adjustResize"

This worked like a charm, Now the header of my app doesn't disappear. Its smoother.

这就像一个咒语,现在我的应用的标题没有消失。它的平滑。

#6


7  

For future readers.

为未来的读者。

I wanted specific control over this issue, so this is what I did:

我想要对这个问题有具体的控制,所以我这样做了:

From a fragment or activity, hide your other views (that aren't needed while the keyboard is up), then restore them to solve this problem:

从一个片段或活动中,隐藏其他视图(在键盘打开时不需要),然后恢复它们来解决这个问题:

            rootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                @Override
                public void onGlobalLayout() {
                    Rect r = new Rect();
                    rootView.getWindowVisibleDisplayFrame(r);
                    int heightDiff = rootView.getRootView().getHeight() - (r.bottom - r.top);

                    if (heightDiff > 100) { // if more than 100 pixels, its probably a keyboard...
                    //ok now we know the keyboard is up...
                        view_one.setVisibility(View.GONE);
                        view_two.setVisibility(View.GONE);

                    }else{
                    //ok now we know the keyboard is down...
                        view_one.setVisibility(View.VISIBLE);
                        view_two.setVisibility(View.VISIBLE);

                    }
                }
            });

#7


7  

For xamarin users add this code to Activity attribute of the MainActivity class,

对于xamarin用户,将此代码添加到MainActivity类的活动属性,

WindowSoftInputMode =Android.Views.SoftInput.AdjustNothing

or you can add this code Window.SetSoftInputMode(Android.Views.SoftInput.AdjustNothing) to the OnCreate method of MainActivity class.

或者,您可以将这个代码Window.SetSoftInputMode(android . view . softinpu .理工学院)添加到MainActivity类的OnCreate方法。

#8


7  

To do this programatically in a fragment you can use following code

要以编程方式在片段中执行此操作,可以使用以下代码

getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

Place this in onResume()

这在onResume()

#9


6  

So far the answers didn't help me as I have a button and a textInput field (side by side) below the textView which kept getting hidden by the keyboard, but this has solved my issue:

到目前为止,这些答案对我没有帮助,因为我在textView下面有一个按钮和一个textInput字段(并排),这个字段一直被键盘隐藏着,但这解决了我的问题:

android:windowSoftInputMode="adjustResize"

#10


6  

Just a single line to be added...

只要加一行……

Add android:windowSoftInputMode="stateHidden|adjustPan" in required activity of your manifest file.

添加android:windowSoftInputMode="stateHidden|调整器",在您的清单文件的需要活动中。

I just got solved :) :)

我刚被解决:)

#11


5  

Add following code to the 'activity' of Manifest file.

将以下代码添加到清单文件的“活动”中。

android:windowSoftInputMode="adjustResize"

#12


4  

This was the best which worked for me

这对我来说是最好的

android:windowSoftInputMode="adjustNothing"

Try it!

试一试!

#13


4  

android:windowSoftInputMode="stateHidden|adjustNothing"

This code works.

这段代码。

#14


2  

The activity's main window will not resize to make room for the soft keyboard. Rather, the contents of the window will be automatically panned so that the current focus is never obscured by the keyboard and users can always see what they are typing.

活动的主窗口将不会调整大小,为软键盘腾出空间。相反,窗口的内容将被自动扫描,以确保当前焦点不会被键盘遮挡,用户总是可以看到他们输入的内容。

android:windowSoftInputMode="adjustPan"

This might be a better solution for what you desired.

这可能是您想要的更好的解决方案。

#15


2  

For Scroll View:

滚动视图:

if after adding android:windowSoftInputMode="stateHidden|adjustPan" in your Android Manifest and still does not work.

如果添加了android:windowSoftInputMode=“状态隐藏的|调整程序”,在您的android Manifest中仍然无效。

It may be affected because when the keyboard appears, it will be into a scroll view and if your button/any objects is not in your scroll view then the objects will follow the keyboard and move its position.

它可能会受到影响,因为当键盘出现时,它将进入一个滚动视图,如果你的按钮/任何对象不在你的滚动视图中,那么对象将跟随键盘并移动它的位置。

Check out your xml where your button is and make sure it is under your scroll View bracket and not out of it.

请检查按钮所在的xml,并确保它位于滚动视图括号内,而不是不在其中。

Hope this helps out. :D

希望这可以帮助。:D

#16


2  

Well i have watched these answers but in my case i fell into the same issue and got refuge through a very handy and easiest solution that involves putting a very small innocent attribute in your Scrollview tag residing in your xml file. That is

我已经看过这些答案了,但在我的例子中,我也遇到了同样的问题,我通过一个非常方便、最简单的解决方案得到了庇护,这个解决方案涉及到在xml文件中的Scrollview标记中放置一个非常小的无害属性。这是

android:isScrollCOntainer="false"

Good luck!

好运!

#17


1  

Try to use this:

尝试使用:

android:windowSoftInputMode="stateHidden|adjustPan"

#18


1  

This code may help you. Use it in your oncreate method.

这段代码可能会对您有所帮助。在oncreate方法中使用它。

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

#19


1  

Include in your manifest file under activity which you want to display .But make sure not using Full screen Activity

在您的清单文件中包含您想要显示的活动,但是请确保不要使用全屏活动

android:windowSoftInputMode="adjustPan"

#20


0  

In my case I needed the keyboard to stay hidden and just after the click of the button my layout needs to be adjusted, so I just added this command in the manifest and it got super right.

在我的例子中,我需要键盘保持隐藏,在点击按钮后,我的布局需要调整,所以我在清单中添加了这个命令,它变得超级正确。

android:windowSoftInputMode="stateHidden|adjustResize"

#21


0  

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

This one is working for me.

这个是为我工作的。


推荐阅读
author-avatar
涛升一舅_250
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有