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

解决Android输入法弹出遮挡输入框的困扰

资源:吊炸天!74款APP完整源码!android界面中点击输入框时弹出输入法如果输入框在底部会出现输入法遮挡输入内容的问题解决办法设置activity的windowsoftinpu

资源:吊炸天!74款APP完整源码!



android 界面中 点击输入框时 弹出输入法 如果输入框在底部 会出现输入法遮挡输入内容的问题

解决办法 设置activity的 window soft input mode 属性,属性具体参看google官方文档或译文(见后面)。

需要备注的是
1.使用adjustResize属性是 如果界面中没有滚动条 需要添加一个滚动条scrollview包裹所有内容,保证resize后 能滚动显示显示不下的内容
2.全屏fullscreen模式时 adjustResize属性失效,属于是一个bug,只能使用adjustPan 来设置焦点,比较悲剧
3.全屏fullscreen模式时 webview adjustPan 偶尔也会失效~~~~~~~~,悲剧一米




PS:
google官方文档:
http://developer.android.com/gui ... -element.html#wsoft


译文
http://www.blogjava.net/zhip/archive/2011/02/14/344258.html


bug:


全屏状态下 adjustResize 不响应 只能用adjustpan,且webview 全屏状态下 adjustpan响应也不够好 有时无响应。

http://code.google.com/p/android/issues/detail?id=5497








[摘]android:windowSoftInputMode属性使用
在AndroidManifest.xml文件中的android:windowSoftInputMode属性使用

The AndroidManifest.xml File

  1.                                     "stateUnchanged", "stateHidden",

  2.                                     "stateAlwaysHidden", "stateVisible",

  3.                                     "stateAlwaysVisible", "adjustUnspecified",

  4.                                     "adjustResize", "adjustPan"] …… >

attributes:

android:windowSoftInputMode

活动的主窗口如何与包含屏幕上的软键盘窗**互。这个属性的设置将会影响两件事情:

1>     软键盘的状态——是否它是隐藏或显示——当活动(Activity)成为用户关注的焦点。

2>     活动的主窗口调整——是否减少活动主窗口大小以便腾出空间放软键盘或是否当活动窗口的部分被软键盘覆盖时它的内容的当前焦点是可见的。

它的设置必须是下面列表中的一个值,或一个”state…”值加一个”adjust…”值的组合。在任一组设置多个值——多个”state…”values,例如&mdash有未定义的结果。各个值之间用|分开。例如:

在这设置的值(除"stateUnspecified"和"adjustUnspecified"以外)将覆盖在主题中设置的值

值 描述

"stateUnspecified" 软键盘的状态(是否它是隐藏或可见)没有被指定。系统将选择一个合适的状态或依赖于主题的设置。这个是为了软件盘行为默认的设置。

"stateUnchanged" 软键盘被保持无论它上次是什么状态,是否可见或隐藏,当主窗口出现在前面时。

"stateHidden" 当用户选择该Activity时,软键盘被隐藏——也就是,当用户确定导航到该Activity时,而不是返回到它由于离开另一个Activity。

"stateAlwaysHidden" 软键盘总是被隐藏的,当该Activity主窗口获取焦点时。

"stateVisible" 软键盘是可见的,当那个是正常合适的时(当用户导航到Activity主窗口时)。

"stateAlwaysVisible" 当用户选择这个Activity时,软键盘是可见的——也就是,也就是,当用户确定导航到该Activity时,而不是返回到它由于离开另一个Activity。

"adjustUnspecified" 它不被指定是否该Activity主窗口调整大小以便留出软键盘的空间,或是否窗口上的内容得到屏幕上当前的焦点是可见的。系统将自动选择这些模式中一种主要依赖于是否窗口的内容有任何布局视图能够滚动他们的内容。如果有这样的一个视图,这个窗口将调整大小,这样的假设可以使滚动窗口的内容在一个较小的区域中可见的。这个是主窗口默认的行为设置。

"adjustResize" 该Activity主窗口总是被调整屏幕的大小以便留出软键盘的空间。

"adjustPan" 该Activity主窗口并不调整屏幕的大小以便留出软键盘的空间。相反,当前窗口的内容将自动移动以便当前焦点从不被键盘覆盖和用户能总是看到输入内容的部分。这个通常是不期望比调整大小,因为用户可能关闭软键盘以便获得与被覆盖内容的交互操作。





bug:

全屏状态下 adjustResize 不响应 只能用adjustpan,且webview 全屏状态下 adjustpan响应也不够好 有时无响应。

http://code.google.com/p/android/issues/detail?id=5497

Issue 5497: adjustResize windowSoftInputMode breaks when activity is fullscreen   
  30 people starred this issue and may be notified of changes. Back to list 


Status:  New 
Owner:  ---- 
Type-Defect
Priority-Medium
ReportedBy-User 


Add a comment below   Reported by  cherylse...@gmail.com , Dec 16, 2009 
I am on Android 1.5 r3.  I have a very simple activity with a vertical
linear layout that contains an edit text, and a text view with a green
background that occupies all extra available space (layout weight = 1). 
When I focus on the edit text field, the keyboard appears and the screen
should get adjusted so that the green text view shrinks vertically
(resizes) and the text is still centered vertically within the visible
green space.  

This works great, except when I make the activity fullscreen - either by
setting the activity's theme to Theme.NoTitleBar.Fullscreen or by
programatically setting the FLAG_FULLSCREEN window flag.  If I use
Theme.NoTitleBar things are fine.

Also, I should mention that our device's screen is landscape (800x480) so I
have implemented a keyboard whose InputMethodService subclass overrides
onEvaluateFullscreenMode, always returning 'false' in order to stay in
'adjust resize keyboard mode' instead of going into 'fullscreen keyboard mode'.
TestAdjustResizeFullscreen.zip 
13.5 KB   Download  
ExpectedResult.png 
24.2 KB   View   Download  

FullscreenResult.png 
11.4 KB   View   Download  


Comment 1 by  burke.e...@gmail.com , Jan 31, 2010 
I see this as well. For my layout, I have a vertical LinearLayout. Within it, I have
these children from top to bottom: TextView, ListView, EditText, and finally a
horizontal LinearLayout, which in turn contains a button.

In my AndroidManifest.xml, I specified android:windowSoftInputMode="adjustResize",
and it works. The ListView shrinks as expected.

But when I change my theme to @android:style/Theme.Light.NoTitleBar.Fullscreen, the
adjustResize fails. My button at the bottom of the screen is obscured, and sometimes
part of the EditText is obscured until I start typing.
Comment 2 by  burke.e...@gmail.com , Jan 31, 2010 
Just to add a bit of detail to my previous comment: I see the failure on Android 1.6
on my G1 phone.
Comment 3 by  burke.e...@gmail.com , Jan 31, 2010 
Also tested on Android 2.1 in emulator - still fails there
Comment 4 by  crazybob...@gmail.com , Mar 1, 2010 
Does someone have a workaround? I suppose I could use a fixed height for my layout 
and tweak it when the keyboard displays, assuming I can compute the size of the 
remaining screen area.
Comment 5 by  jame...@gmail.com , Mar 7, 2010 
Reproducible on the Nexus One with 2.1-update1
Comment 6 by  m.kin...@gmail.com , Apr 24, 2010 
I would like to voice my opinion that a notification when the keyboard goes away
would be very helpful. I too am using a Fullscreen view, so I am stuck without an
option to know when the keyboard disappears.

I _am_ using a fixed height for the keyboard because the current mechanisms don't
seem to work for fullscreen. But when the user presses the back button, the IME eats
it and there's no notification or onSizeChanged to know when the keyboard goes away.

Why is it so hard to provide a notification when the keyboard goes away?
Comment 7 by  lucian...@gmail.com , Aug 5, 2010 
Hello i have a relativeLayout at the top, then below i have a listView in the center and finaly at the bottom i have other relativeLayout with an editText and a button inside. I want to the listview resize when click the editText and the IME(virtual keyboard) appear. If i put adjustResize in the manifest, the listview is resized to leave space for the IME, but the relativeLayout with the editText that is below is cover by the IME and i can't see what i am writing. If i put adjustPan, the keyboard push up all, the listview is not resized and i loose the top relativeLayout. D: PLEASE HELP!!!! 
Comment 8 by  revanth....@gmail.com , Sep 9, 2010 
i am facing the same issue what others are facing...if any one solve please let me know.
Comment 9 by  falar...@gmail.com , Oct 12, 2010 
I'm running into this same issue with an activity that has an embedded WebView. The input field keyboard focus doesn't work right without adjustResize turned on, but adjustResize doesn't work in full screen mode. This means that this is the only activity in my app that shows the status bar. At the very least there should be something in the documentation that says that this combination doesn't (or isn't supposed to) work.
Comment 10 by project member  romannu...@google.com , Oct 13, 2010 
Relevant post from hackbod:
https://groups.google.com/group/ ... sg/5690ac3a9819a53b
Comment 12 by  whoop....@gmail.com , Feb 1, 2011 
Please patch the OS so that adjustPan is honored in a fullscreen webview : 

When a keyboard slides up in a fullscreen webview, the input field clicked on should slide up (remaining visible). 

Otherwise, web designers cannot place input fields on the bottom 2/3rds of a screen.
Comment 13 by  hopfc...@gmail.com , Feb 23, 2011 
I can confirm this issue. As soon as you set your activity to fullscreen the windowSoftInputMode:adjustResize will no longer work.

I hope this will get fixed soon as this break alot of layout ideas.
Comment 14 by  jasond...@gmail.com , Mar 16, 2011 
Still an issue. 2.2.1
Comment 16 by  guiha...@gmail.com , Sep 9, 2011 
The same issue occurs in Android 3.1.

The notification is also NOT SENT when the device is in LANDSCAPE mode in versions prior to 3.0. (actually i tested it in a Xoom with 3.1 and the notification is sent in LANDSCAPE mode, so i'm just assuming it was fixed in 3.0). The fullscreen problem also occurs in xoom, even if there's no screen diference between full screen and non-full screen in the Xoom.
Comment 17 by akasek, Oct 7, 2011 
The last two comments have confirmed Froyo and Honeycomb. I'll confirm Gingerbread also (2.3.4)

Also, I interpret the linked post in comment 10 from Diane Hackborn as acknowledgement that this is an unintended effect and should not be the case.

Would be nice if this was fixed, because adjustPan does bad things to layouts with headers or footers (pushing them offscreen).  In an application which allows the user to select whether to hide the status bar or not, the time when the most space is available is the time when header and footer elements will become unaccessible.  It doesn't make sense to behave this way. 




Java和Android架构

Java和Android架构是一个数万人关注的探讨Java和Android开发的公众号,分享和原创最有价值的干货文章,让你成为这方面的大牛!

我们探讨android和Java开发最前沿的技术:android性能优化 ,插件化,跨平台,动态化,加固和反破解等,也讨论设计模式/软件架构等。由群来自BAT的工程师组成的团队

关注即送红包,回复:“百度” 、“阿里”、“腾讯” 有惊喜!!!关注后可用入微信群。群里都是来自百度阿里腾讯的大牛。

欢迎关注我们,一起讨论技术,扫描和长按下方的二维码可快速关注我们。搜索微信公众号:JANiubility。

公众号:JANiubility




推荐阅读
  • 优化ListView性能
    本文深入探讨了如何通过多种技术手段优化ListView的性能,包括视图复用、ViewHolder模式、分批加载数据、图片优化及内存管理等。这些方法能够显著提升应用的响应速度和用户体验。 ... [详细]
  • Explore a common issue encountered when implementing an OAuth 1.0a API, specifically the inability to encode null objects and how to resolve it. ... [详细]
  • 将Web服务部署到Tomcat
    本文介绍了如何在JDeveloper 12c中创建一个Java项目,并将其打包为Web服务,然后部署到Tomcat服务器。内容涵盖从项目创建、编写Web服务代码、配置相关XML文件到最终的本地部署和验证。 ... [详细]
  • 本文介绍如何使用布局文件在Android应用中排列多行TextView和Button,使其占据屏幕的特定比例,并提供示例代码以帮助理解和实现。 ... [详细]
  • 本文详细介绍了 GWT 中 PopupPanel 类的 onKeyDownPreview 方法,提供了多个代码示例及应用场景,帮助开发者更好地理解和使用该方法。 ... [详细]
  • 本文将介绍如何编写一些有趣的VBScript脚本,这些脚本可以在朋友之间进行无害的恶作剧。通过简单的代码示例,帮助您了解VBScript的基本语法和功能。 ... [详细]
  • Explore how Matterverse is redefining the metaverse experience, creating immersive and meaningful virtual environments that foster genuine connections and economic opportunities. ... [详细]
  • 导航栏样式练习:项目实例解析
    本文详细介绍了如何创建一个具有动态效果的导航栏,包括HTML、CSS和JavaScript代码的实现,并附有详细的说明和效果图。 ... [详细]
  • 本文详细介绍了如何在Linux系统上安装和配置Smokeping,以实现对网络链路质量的实时监控。通过详细的步骤和必要的依赖包安装,确保用户能够顺利完成部署并优化其网络性能监控。 ... [详细]
  • DNN Community 和 Professional 版本的主要差异
    本文详细解析了 DotNetNuke (DNN) 的两种主要版本:Community 和 Professional。通过对比两者的功能和附加组件,帮助用户选择最适合其需求的版本。 ... [详细]
  • Python自动化处理:从Word文档提取内容并生成带水印的PDF
    本文介绍如何利用Python实现从特定网站下载Word文档,去除水印并添加自定义水印,最终将文档转换为PDF格式。该方法适用于批量处理和自动化需求。 ... [详细]
  • 在当前众多持久层框架中,MyBatis(前身为iBatis)凭借其轻量级、易用性和对SQL的直接支持,成为许多开发者的首选。本文将详细探讨MyBatis的核心概念、设计理念及其优势。 ... [详细]
  • 本文介绍如何通过 JavaScript 实现一个基于鼠标坐标的 Tooltip 弹出层,详细解释了如何获取窗口和文档的尺寸及滚动位置,并优化了代码结构。 ... [详细]
  • 在现代Web应用中,当用户滚动到页面底部时,自动加载更多内容的功能变得越来越普遍。这种无刷新加载技术不仅提升了用户体验,还优化了页面性能。本文将探讨如何实现这一功能,并介绍一些实际应用案例。 ... [详细]
  • 利用Selenium与ChromeDriver实现豆瓣网页全屏截图
    本文介绍了一种使用Selenium和ChromeDriver结合Python代码,轻松实现对豆瓣网站进行完整页面截图的方法。该方法不仅简单易行,而且解决了新版Selenium不再支持PhantomJS的问题。 ... [详细]
author-avatar
OH-MQNZ_259
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有