popupwindow中EditText获取焦点后自动弹出软键盘
关于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获取焦点后自动弹出软键盘的更多相关文章
- android开发中防止刚进入activity时edittext获取焦点,自动弹出软键盘
刚进入activity的时候,如果布局组件有edittext的话,往往edittext会获取焦点,自动弹出软键盘,影响整个界面的视觉效果.解决方法如下: 可以在edittext的父布局结构中(例如 ...
- android开发中防止刚进入activity时edittext获取焦点,防止自动自动弹出软键盘
刚进入activity的时候,如果布局组件有edittext的话,往往edittext会获取焦点,自动弹出软键盘,影响整个界面的视觉效果.解决方法如下: 可以在edittext的父布局结构中(例如Li ...
- Android PopupWindow中EditText获取焦点自动弹出软键盘
公司的项目中要求在点击搜索的时候弹出一个搜索框,搜索框中有一个EditText,用于数据搜索关键字,要求在弹出PopupWindow的时候自动弹出软键盘,原以为只要写上着两行代码可以搞的问题: Inp ...
- 【转】EditText获取焦点不自动弹出键盘设置--失去焦点的方法,不错
原文网址:http://zouhuajian01.blog.163.com/blog/static/1176987720121128115813176/ 当我们在activity中加入EditText ...
- [转]android自动弹出软键盘(输入键盘)
转自:http://www.devdiv.com/home.php?mod=space&uid=65729&do=blog&id=11847 很多应用中对于一个界面比如进入搜索 ...
- Android 显示Dialog的同时自动弹出软键盘;
需求大致就是这样的:用户点击按钮弹出Dialog,Dialog中有输入框,然后Dialog弹出后要自动弹出软键盘:(如果让用户自己手动点击输入框再弹出软键盘的话,用户体验太差了): 好的,需求大致就是 ...
- android自动弹出软键盘(输入键盘)
很多应用中对于一个界面比如进入搜索界面或者修改信息等等情况,为了用户体验应该自动弹出软键盘而不是让用户主动点击输入框才弹出(因为用户进入该界面必然是为了更改信息).具体实现这种效果如下: [代 ...
- Android 自动弹出软键盘(输入键盘)
很多应用中对于一个界面比如进入搜索界面或者修改信息等等情况,为了用户体验应该自动弹出软键盘而不是让用户主动点击输入框才弹出(因为用户进入该界面必然是为了更改信息).具体实现这种效果如下: EditTe ...
- html5自动弹出软键盘的方法
html5自动弹出软键盘的方法<pre> <textarea placeholder="说点什么......" autofocus="autofocus ...
随机推荐
- [LeetCode] Find Smallest Letter Greater Than Target 找比目标值大的最小字母
Given a list of sorted characters letters containing only lowercase letters, and given a target lett ...
- Python系列之 - 线程基础
一.什么是线程 线程:顾名思义,就是一条流水线工作的过程,一条流水线必须属于一个车间,一个车间的工作过程是一个进程 所以,进程只是用来把资源集中到一起(进程只是一个资源单位,或者说资源集合),而线程才 ...
- Linux使用踩坑记
Ubuntu安装坑: 1.对于新手第一次安装ubuntu,特殊情况会出现因为分辨率问题导致安装界面不全,无法进行下一步操作. 解决方案:使用alt+鼠标左键拖动屏幕Linux文件名乱码问题: 2.因为 ...
- [HNOI 2002]营业额统计
Description 营业额统计 Tiger最近被公司升任为营业部经理,他上任后接受公司交给的第一项任务便是统计并分析公司成立以来的营业情况. Tiger拿出了公司的账本,账本上记录了公司成立以来每 ...
- [USACO13OPEN]照片Photo
题目描述 Farmer John has decided to assemble a panoramic photo of a lineup of his N cows (1 <= N < ...
- [Apio2009]Atm
题目描述 输入 第一行包含两个整数N.M.N表示路口的个数,M表示道路条数.接下来M行,每行两个整数,这两个整数都在1到N之间,第i+1行的两个整数表示第i条道路的起点和终点的路口编号.接下来N行,每 ...
- ●BZOJ 4559 [JLoi2016]成绩比较(容斥)
题链: http://www.lydsy.com/JudgeOnline/problem.php?id=4559 题解: 容斥,拉格朗日插值法. 结合网上的另一种方法,以及插值法,可以把本题做到 O( ...
- 作为开发也要了解的 mysql 优化思路
作为开发人员,数据库知识掌握的可能不是很深入,但是一些基本的技能还是要有时间学习一下的.作为一个数据库菜鸟,厚着脸皮来总结一下 mysql 的基本的不能再基本的优化方法. 为了更好的说明,我假想出来了 ...
- 利用 socket 发送 get/post 请求
思路:利用 fsockopen 函数与要请求的主机建立一个通信通道,再将请求行.头信息.主体信息通过这个通道传输给主机实现请求的发送.利用这种方式发送 get 请求就是常说的小偷程序,发送 post ...
- jquery easyui datagrid detailview groupview添加自定义视图view
var myview = $.extend({}, $.fn.datagrid.defaults.view, { onAfterRender: function (target) { $.fn.dat ...