关于popupwindow中EditText获取焦点后自动弹出软键盘的问题,玩过手机qq或空间的童鞋应该知道,再点击评论时会弹出一个编辑框,并且伴随软键盘一起弹出是不是很方便啊,下面我们就来讲一下实现方法,先看效果:

实现过程其实就是在listview的适配器Adapter中给"评论"这个所在的这个空间设置一个监听,当点击评论时,弹出popup,并异步弹出软键盘,看一下我的适配器中的代码片段:

//评论设置监听
		holder.pinglun.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				showPopup(holder.pinglun);
				popupInputMethodWindow();
				//Toast.makeText(activity, "评论", Toast.LENGTH_SHORT).show();
			}
		});

接下来看showPopup弹出popupwindow具体实现方法:

private void showPopup(View parent){
		if (popWindow == null) {
			LayoutInflater layoutInflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			View view = layoutInflater.inflate(R.layout.popwindow_pinglun,null);
			// 创建一个PopuWidow对象
			popWindow = new PopupWindow(view,LinearLayout.LayoutParams.FILL_PARENT,100,true);
		}
//popupwindow弹出时的动画		popWindow.setAnimationStyle(R.style.popupWindowAnimation);
		// 使其聚集 ,要想监听菜单里控件的事件就必须要调用此方法
		popWindow.setFocusable(true);
		// 设置允许在外点击消失
		popWindow.setOutsideTouchable(false);
		// 设置背景,这个是为了点击“返回Back”也能使其消失,并且并不会影响你的背景
		popWindow.setBackgroundDrawable(new BitmapDrawable());
		//软键盘不会挡着popupwindow
		popWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
		//设置菜单显示的位置
		popWindow.showAtLocation(parent, Gravity.BOTTOM, 0, 0);
		//监听菜单的关闭事件
		popWindow.setOnDismissListener(new OnDismissListener() {
			@Override
			public void onDismiss() {
							}
		});
		//监听触屏事件
		popWindow.setTouchInterceptor(new OnTouchListener() {
			public boolean onTouch(View view, MotionEvent event) {
				return false;
			}
		});
	}

popupwindow布局如下:

先看效果:

再看代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/title_background" >

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:padding="5dp" >

        <TextView
            android:id="@+id/at"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:layout_marginLeft="5dp"
            android:background="@drawable/qz_icon_at_normal" />

        <TextView
            android:id="@+id/biaoqing"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_marginLeft="10dp"
            android:layout_toRightOf="@+id/at"
            android:background="@drawable/qz_icon_expression_normal" />

        <EditText
            android:id="@+id/pinglun"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="5dp"
            android:layout_toLeftOf="@+id/fabiao"
            android:layout_toRightOf="@+id/biaoqing"
            android:background="@drawable/edit_bg_all"
            android:focusable="true"
            android:hint="来说一句吧..." />

        <Button
            android:id="@+id/fabiao"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:layout_marginRight="5dp"
            android:background="@drawable/title_write_btn_normal"
            android:padding="8dp"
            android:text="发表"
            android:textColor="#FFFFFF"
            android:textSize="14sp" />
    </RelativeLayout>

</RelativeLayout>

其中的图片什么的我就不贴了,大家可以自己找一下,然后看弹出软键盘的实现方法,注意这个需要异步操作:

private void popupInputMethodWindow() {
	    handler.postDelayed(new Runnable() {
	        @Override
	        public void run() {
	            imm = (InputMethodManager) pinglun.getContext().getSystemService(Service.INPUT_METHOD_SERVICE);
	            imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
	        }
	    }, 0);
	}  

好了,本文就讲到这里,有类似需求的同学,可以依照我的方法试下,popupwindow的布局我只是简单的做了下,还不够美观,大家可以设计的更美观一下,谢谢大家!

popupwindow中EditText获取焦点后自动弹出软键盘的更多相关文章

  1. android开发中防止刚进入activity时edittext获取焦点,自动弹出软键盘

    刚进入activity的时候,如果布局组件有edittext的话,往往edittext会获取焦点,自动弹出软键盘,影响整个界面的视觉效果.解决方法如下:   可以在edittext的父布局结构中(例如 ...

  2. android开发中防止刚进入activity时edittext获取焦点,防止自动自动弹出软键盘

    刚进入activity的时候,如果布局组件有edittext的话,往往edittext会获取焦点,自动弹出软键盘,影响整个界面的视觉效果.解决方法如下: 可以在edittext的父布局结构中(例如Li ...

  3. Android PopupWindow中EditText获取焦点自动弹出软键盘

    公司的项目中要求在点击搜索的时候弹出一个搜索框,搜索框中有一个EditText,用于数据搜索关键字,要求在弹出PopupWindow的时候自动弹出软键盘,原以为只要写上着两行代码可以搞的问题: Inp ...

  4. 【转】EditText获取焦点不自动弹出键盘设置--失去焦点的方法,不错

    原文网址:http://zouhuajian01.blog.163.com/blog/static/1176987720121128115813176/ 当我们在activity中加入EditText ...

  5. [转]android自动弹出软键盘(输入键盘)

    转自:http://www.devdiv.com/home.php?mod=space&uid=65729&do=blog&id=11847 很多应用中对于一个界面比如进入搜索 ...

  6. Android 显示Dialog的同时自动弹出软键盘;

    需求大致就是这样的:用户点击按钮弹出Dialog,Dialog中有输入框,然后Dialog弹出后要自动弹出软键盘:(如果让用户自己手动点击输入框再弹出软键盘的话,用户体验太差了): 好的,需求大致就是 ...

  7. android自动弹出软键盘(输入键盘)

        很多应用中对于一个界面比如进入搜索界面或者修改信息等等情况,为了用户体验应该自动弹出软键盘而不是让用户主动点击输入框才弹出(因为用户进入该界面必然是为了更改信息).具体实现这种效果如下: [代 ...

  8. Android 自动弹出软键盘(输入键盘)

    很多应用中对于一个界面比如进入搜索界面或者修改信息等等情况,为了用户体验应该自动弹出软键盘而不是让用户主动点击输入框才弹出(因为用户进入该界面必然是为了更改信息).具体实现这种效果如下: EditTe ...

  9. html5自动弹出软键盘的方法

    html5自动弹出软键盘的方法<pre> <textarea placeholder="说点什么......" autofocus="autofocus ...

随机推荐

  1. drupal 8 之 captcha模块

    captcha模块的作用: 添加验证码表单 一.模块下载 https://www.drupal.org/project/captcha 二.安装模块 [扩展]>[+安装新的模块] 在模块页面,复 ...

  2. Angular1.x使用小结

    之前工作以Angular1.x为主,主要做业务系统,以后工作中技术栈可能以vue为主,在此对Angular1.x的使用做一个简单总结,这里使用1.5+版本. 基本概念 1.依赖注入 依赖注入,在ang ...

  3. json pickle ;shelve

    import json dic={'name':'alex'} """ f=open("new_hello","w") # dic ...

  4. ●BZOJ 3561 DZY Loves Math VI

    题链: http://www.lydsy.com/JudgeOnline/problem.php?id=3561 题解: 莫比乌斯反演 $$\begin{aligned}ANS&=\sum_{ ...

  5. VK Cup 2017 - Round 1

    和FallDream组队瞎打一通--B两个人写的都挂了233,最后只剩下FallDream写的A和我写的C,最后我yy了个E靠谱做法结果打挂了,结束之后改了改就A了,难受. AC:AC Rank:18 ...

  6. poj 1269 线段与线段相交

    Intersecting Lines Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 13605   Accepted: 60 ...

  7. Django中Form的基本使用

    from django import forms from django.forms import fields class UserInfo(forms.Form): username = fiel ...

  8. 手机上的ROM与RAM

    ROM:read only memory翻译为只读存储器. RAM:read access memory翻译为随机存储器. 下面是一张手机的配置参数表. 简单来说,RAM就是真正意义上的内存,而ROM ...

  9. MySQL 内连接与外连接

    1.内连接 MySQL中,join,cross join,inner join 是等价的. 2.外连接 2.1 左外连接 left join 2.2 右外连接  right join 3.连接条件 使 ...

  10. IOS UITextView支持输入、复制、粘贴、剪切自定义表情

    UITextView是ios的富文本编辑控件,除了文字还可以插入图片等.今天主要介绍一下UITextView对自定义表情的处理. 1.首先识别出文本中的表情文本,然后在对应的位置插入NSTextAtt ...