热门标签 | 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.

这个是为我工作的。


推荐阅读
  • android listview OnItemClickListener失效原因
    最近在做listview时发现OnItemClickListener失效的问题,经过查找发现是因为button的原因。不仅listitem中存在button会影响OnItemClickListener事件的失效,还会导致单击后listview每个item的背景改变,使得item中的所有有关焦点的事件都失效。本文给出了一个范例来说明这种情况,并提供了解决方法。 ... [详细]
  • 后台获取视图对应的字符串
    1.帮助类后台获取视图对应的字符串publicclassViewHelper{将View输出为字符串(注:不会执行对应的ac ... [详细]
  • 《数据结构》学习笔记3——串匹配算法性能评估
    本文主要讨论串匹配算法的性能评估,包括模式匹配、字符种类数量、算法复杂度等内容。通过借助C++中的头文件和库,可以实现对串的匹配操作。其中蛮力算法的复杂度为O(m*n),通过随机取出长度为m的子串作为模式P,在文本T中进行匹配,统计平均复杂度。对于成功和失败的匹配分别进行测试,分析其平均复杂度。详情请参考相关学习资源。 ... [详细]
  • CF:3D City Model(小思维)问题解析和代码实现
    本文通过解析CF:3D City Model问题,介绍了问题的背景和要求,并给出了相应的代码实现。该问题涉及到在一个矩形的网格上建造城市的情景,每个网格单元可以作为建筑的基础,建筑由多个立方体叠加而成。文章详细讲解了问题的解决思路,并给出了相应的代码实现供读者参考。 ... [详细]
  • Android开发实现的计时器功能示例
    本文分享了Android开发实现的计时器功能示例,包括效果图、布局和按钮的使用。通过使用Chronometer控件,可以实现计时器功能。该示例适用于Android平台,供开发者参考。 ... [详细]
  • 深入理解CSS中的margin属性及其应用场景
    本文主要介绍了CSS中的margin属性及其应用场景,包括垂直外边距合并、padding的使用时机、行内替换元素与费替换元素的区别、margin的基线、盒子的物理大小、显示大小、逻辑大小等知识点。通过深入理解这些概念,读者可以更好地掌握margin的用法和原理。同时,文中提供了一些相关的文档和规范供读者参考。 ... [详细]
  • 本文内容为asp.net微信公众平台开发的目录汇总,包括数据库设计、多层架构框架搭建和入口实现、微信消息封装及反射赋值、关注事件、用户记录、回复文本消息、图文消息、服务搭建(接入)、自定义菜单等。同时提供了示例代码和相关的后台管理功能。内容涵盖了多个方面,适合综合运用。 ... [详细]
  • 本文介绍了在Win10上安装WinPythonHadoop的详细步骤,包括安装Python环境、安装JDK8、安装pyspark、安装Hadoop和Spark、设置环境变量、下载winutils.exe等。同时提醒注意Hadoop版本与pyspark版本的一致性,并建议重启电脑以确保安装成功。 ... [详细]
  • Google Play推出全新的应用内评价API,帮助开发者获取更多优质用户反馈。用户每天在Google Play上发表数百万条评论,这有助于开发者了解用户喜好和改进需求。开发者可以选择在适当的时间请求用户撰写评论,以获得全面而有用的反馈。全新应用内评价功能让用户无需返回应用详情页面即可发表评论,提升用户体验。 ... [详细]
  • 动态规划算法的基本步骤及最长递增子序列问题详解
    本文详细介绍了动态规划算法的基本步骤,包括划分阶段、选择状态、决策和状态转移方程,并以最长递增子序列问题为例进行了详细解析。动态规划算法的有效性依赖于问题本身所具有的最优子结构性质和子问题重叠性质。通过将子问题的解保存在一个表中,在以后尽可能多地利用这些子问题的解,从而提高算法的效率。 ... [详细]
  • 本文介绍了游标的使用方法,并以一个水果供应商数据库为例进行了说明。首先创建了一个名为fruits的表,包含了水果的id、供应商id、名称和价格等字段。然后使用游标查询了水果的名称和价格,并将结果输出。最后对游标进行了关闭操作。通过本文可以了解到游标在数据库操作中的应用。 ... [详细]
  • 自动轮播,反转播放的ViewPagerAdapter的使用方法和效果展示
    本文介绍了如何使用自动轮播、反转播放的ViewPagerAdapter,并展示了其效果。该ViewPagerAdapter支持无限循环、触摸暂停、切换缩放等功能。同时提供了使用GIF.gif的示例和github地址。通过LoopFragmentPagerAdapter类的getActualCount、getActualItem和getActualPagerTitle方法可以实现自定义的循环效果和标题展示。 ... [详细]
  • 高质量SQL书写的30条建议
    本文提供了30条关于优化SQL的建议,包括避免使用select *,使用具体字段,以及使用limit 1等。这些建议是基于实际开发经验总结出来的,旨在帮助读者优化SQL查询。 ... [详细]
  • FeatureRequestIsyourfeaturerequestrelatedtoaproblem?Please ... [详细]
  • Go GUIlxn/walk 学习3.菜单栏和工具栏的具体实现
    本文介绍了使用Go语言的GUI库lxn/walk实现菜单栏和工具栏的具体方法,包括消息窗口的产生、文件放置动作响应和提示框的应用。部分代码来自上一篇博客和lxn/walk官方示例。文章提供了学习GUI开发的实际案例和代码示例。 ... [详细]
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社区 版权所有