---
title: "Android PopUpWindow 软键盘"
author: "trinityblood"
date: "2012-12-03T01:56:57Z"
tags: []
categories: ["移动开发"]
slug: "android-popupwindow"
draft: false
lastmod: "2012-12-03T01:56:57Z"
id: 1739911
url: "https://trinityblood.iteye.com/blog/1739911"
---

点击EditText的时候，同时显示PopUpWindow和软键盘


```java

@Override
warnSearch.setOnTouchListener(this);
public boolean onTouch(View v, MotionEvent event) {
    // TODO Auto-generated method stub
    Log.d(TAG, "edit onTouch");
    if (event.getAction() == MotionEvent.ACTION_UP) {
    	searchViewShow();
    }
    return false;
}
public void searchViewShow(){
    popUpWindow = new PopupWindow(searchView, screenWidth, 60);
    // 使其获取焦点
    // popUpWindow.setFocusable(true);
    // 设置允许在外点击消失
    popUpWindow.setOutsideTouchable(true);
    // 这个是为了点击“返回Back”也能使其消失，并且并不会影响你的背景
    popUpWindow.setBackgroundDrawable(new BitmapDrawable());
    // 显示在warnSearch的下面(warnSearch是一个EditText)
    popUpWindow.showAsDropDown(warnSearch, 0, 0);
}

```


实现这个效果的关键是：下面这句代码是一定不能有的，所以我注释掉le

```java

popUpWindow.setFocusable(true);

```