activity中界面中edittext自动获取焦点(软键盘弹出)解决

最近在做开发的时候遇到个比较烦的问题就是 我的某个activity页面中有editText,在一进去就会调用软键盘,这样看起来不美观,所以看了下api

http://developer.android.com/guide/topics/manifest/activity-element.html(要翻墙)

在<Activity>节点下也就是在manifest文件的配置activity节点的时候需要配置

android:windowSoftInputMode 这个属性来控制软键盘的模式。我摘录了一下api  相关软键盘的片段如下:

android:windowSoftInputMode

  • How the main window of the activity interacts with the window containing the on-screen soft keyboard. The setting for this attribute affects two things:

    The setting must be one of the values listed in the following table, or a combination of one "state..." value plus one "adjust..." value. Setting multiple values in either group — multiple "state..." values, for example — has undefined results. Individual values are separated by a vertical bar (|). For example:

    <activity android:windowSoftInputMode="stateVisible|adjustResize" . . . >

    Values set here (other than "stateUnspecified" and "adjustUnspecified") override values set in the theme.

    Value Description
    "stateUnspecified" The state of the soft keyboard (whether it is hidden or visible) is not specified. The system will choose an appropriate state or rely on the setting in the theme.

    This is the default setting for the behavior of the soft keyboard.

    "stateUnchanged" The soft keyboard is kept in whatever state it was last in, whether visible or hidden, when the activity comes to the fore.
    "stateHidden" The soft keyboard is hidden when the user chooses the activity — that is, when the user affirmatively navigates forward to the activity, rather than backs into it because of leaving another activity.
    "stateAlwaysHidden" The soft keyboard is always hidden when the activity‘s main window has input focus.
    "stateVisible" The soft keyboard is visible when that‘s normally appropriate (when the user is navigating forward to the activity‘s main window).
    "stateAlwaysVisible" The soft keyboard is made visible when the user chooses the activity — that is, when the user affirmatively navigates forward to the activity, rather than backs into it because of leaving another activity.
    "adjustUnspecified" It is unspecified whether the activity‘s main window resizes to make room for the soft keyboard, or whether the contents of the window pan to make the current focus visible on-screen. The system will automatically select one of these modes depending on whether the content of the window has any layout views that can scroll their contents. If there is such a view, the window will be resized, on the assumption that scrolling can make all of the window‘s contents visible within a smaller area.

    This is the default setting for the behavior of the main window.

    "adjustResize" The activity‘s main window is always resized to make room for the soft keyboard on screen.
    "adjustPan" The activity‘s main window is not resized to make room for the soft keyboard. Rather, the contents of the window are automatically panned so that the current focus is never obscured by the keyboard and users can always see what they are typing. This is generally less desirable than resizing, because the user may need to close the soft keyboard to get at and interact with obscured parts of the window.

    This attribute was introduced in  API Level 3.

    浏览了下大概了解下也就是说这个配置主要是做两件事请

    1、当activity获取焦点的时候来设置软键盘是否可见。

    2、(在软键盘变小的时候留出空间,或者activity包含一个软键盘布局同时这个activity获取焦点的时候【pan 在这里翻译的应该是面板,学过java GUI 的都知道有个panle】)调整以适应activity 的大小。

    同时这有很多独立的属性可以去设置,如果你想要设置的属性在其中没有的话你可以尝试着用以上的属性组合一下,只要组合的时候用“|”分开就好了。

  • 跑题了 ,我们要的效果是在当前的activity中有edittext,但是默认不弹出,只有当获取焦点的时候才弹出软键盘,那么我们根据属性可以看下

adjustUnspecified | stateHidden 这个组合起来应该可以达到我们要的效果。因此我们在activity的节点上配置入下:< Activity   android:windowSoftInputMode="stateHidden|adjustUnspecified">

其他的效果可以根据api文档说明进行设置。

 英语水平有限,欢迎指正错误 
 /**
 *
 *  
 **/
时间: 2024-08-02 18:01:24

activity中界面中edittext自动获取焦点(软键盘弹出)解决的相关文章

edittext禁止android软键盘弹出

1. EditText ed=(EditText) findViewById(R.id.test); ed.clearFocus(); 2. 在AndroidMainfest.xml中选择哪个activity,设置windowSoftInputMode属性为adjustUnspecified|stateHidden 比如:<activity android:name=".Main" android:label="@string/app_name" androi

Android软键盘弹出,界面整体上移的问题

AndroidManifest.xml文件中界面对应的<activity>里加入 android:windowSoftInputMode="adjustPan" 键盘就会覆盖屏幕 android:windowSoftInputMode="stateVisible|adjustResize" 屏幕整体上移 Android软键盘弹出,界面整体上移的问题

android软键盘弹出引起的各种不适终极解决方案

很多写登录界面的开发者都会遇到一个问题:那就是在登录界面时,当你点击输入框时,下边的按钮有时会被输入框挡住,这个不利于用户的体验,所以很多人希望软键盘弹出时,也能把按钮挤上去.很多开发者想要监听键盘的状态,这无疑是一个很麻烦的做法. 我们可以在AndroidManifest.xml的Activity设置属性:android:windowSoftInputMode = "adjustResize" ,软键盘弹出时,要对主窗口布局重新进行布局,并调用onSizeChanged方法,切记一点

关于软键盘弹出的问题

最近在做一个项目,大部分页面由fragment实现,需要发帖功能,在界面上部分为EditText,右下有一个发送按钮,下面总结一下遇到的问题: 没有进行软键盘弹出和EditText获取焦点配置时,跳转到发帖页面,EditText自动获取焦点,软键盘弹出,但偶而出现弹出的软键盘覆盖发送按钮的情况 解决方法是通过设置manifest文件中activity属性如下,确保软键盘弹出时为挤压上面显示,而不是覆盖 <activity android:name=".ui.activity.MainAct

Android 软键盘弹出时布局内指定内容上移实现及问题解决

Android SDK目前提供的软键盘弹出模式接口只有两种: 一是弹出时自动回冲界面,将所有元素上顶, 一种则是不重绘界面,直接将控件元素遮住,   没有其他模式,如果想实现其他效果,光使用系统接口是不行的.   解决方法:   第一步:给想要被顶上去的内容嵌套一个 ScrollView :   <ScrollView     android:layout_width="match_parent"     android:layout_height="0dp"

Android软键盘弹出时布局问题

最近项目需要做一个类似聊天室的模块,基于Socket实现的,这部分稍后一段时间再做总结,功能上的相关点都实现了小例子也做出来了,最后发现一个比较腻歪的问题就是软键盘弹出时总是会把标题“挤出”屏幕,(无论标题是写在布局中还是仿照theme的方式添加到style中),输入时有失观赏如下图:      隐隐感觉之前项目一直有类似问题,只不过一般只在登陆界面,无伤大雅,用户输入后一掠而过,可以忽略,但这个页面这么处理确实不太美观. 查了下此类问题大致两种思路解决:         一.调整布局在底层使用

Android软键盘弹出,布局移动

在项目的androidmanifest.xml文件中界面对应的<activity>里加入 android:windowsoftinputmode="adjustpan"这样键盘就会覆盖屏幕.. 如果不想键盘覆盖屏幕,想让屏幕整体上移,就加入属性android:windowsoftinputmode="statevisible|adjustresize" Android软键盘弹出,布局移动,布布扣,bubuko.com

Android不自动弹出软键盘和不让软键盘弹出挤压图形

软键盘弹出挤压图形很变态,设计好的模型会在软件盘弹出数据变得丑陋无比,为了保持不变,只需要在 Manifest.xml 相应的 Activity 里添加 android:windowSoftInputMode="adjustPan|stateHidden" 为了不让软件盘弹出,如果是Activity的话,可以直接添加如下代码解决自动弹出软键盘的问题 <activity android:name="com.guandehao.baobiao.B_KuCunBaoBiao&

Android软键盘弹出,覆盖h5页面输入框问题

之前我们在使用vue进行 h5 表单录入的过程中,遇到了Android软键盘弹出,覆盖 h5页面 输入框 问题,在此进行回顾并分享给大家: 系统:Android 条件:当输入框在可视区底部或者偏下的位置 触发条件:输入框获取焦点,弹出软键盘 表现:软键盘 覆盖 h5页面中的输入框 问题分析: 1.发现问题:当前页面中box为flex布局,内容为上下固定高,中间自适应(中间区域内容过多会出现滚动条,input框在wrapper的底部),input获取焦点,手机键盘弹出,input未上移到可视区内,

如何解决软键盘弹出引起的各种不适

1.如何解决软键盘弹出引起的各种不适 2.android软键盘弹出引起的各种不适终极解决方案 3.android软键盘弹出引起的各种不适终极解决方案 4.android软键盘弹出,会把原来的界面挤上去的问题 处理方法 5.Android 关于弹出键盘问题的几种情况和解决方案 6.Android 弹出软键盘问题(最终解决方法) 7.Android 软键盘显示隐藏监听解决方案