1.软键盘弹出时不会改变布局(覆盖页面的效果)

android:windowSoftInputMode="adjustPan"
2、软键盘弹出时不会覆盖popuwindow
setSoftInputMode(PopupWindow.INPUT_METHOD_NEEDED);
setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
3.popuwindow显示在页面底部,弹出时被软键盘顶
myInput.showAtLocation(findViewById(android.R.id.content),Gravity.BOTTOM,0,0);


4.源码
 4.1popupwindow的布局(自定义)
 public class MyInput extends PopupWindow {
  private Context context; private View view;
   public MyInput(Context context){
this.context=context;
init();
   }public void init(){
   LayoutInflater inflater=LayoutInflater.from(context);
view =inflater.inflate(R.layout.myinput,null);
this.setWidth(getScreenSize()[0]);
this.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
setBackgroundDrawable(new ColorDrawable(0x00000000));
setOutsideTouchable(true);
setFocusable(true);
setSoftInputMode(PopupWindow.INPUT_METHOD_NEEDED);
setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
setContentView(view);
}
@Override
public void showAsDropDown(View anchor) {
// TODO Auto-generated method stub
super.showAsDropDown(anchor);
showPopuWindow();
}
@Override
public void showAsDropDown(View anchor, int xoff, int yoff) {
// TODO Auto-generated method stub
super.showAsDropDown(anchor, xoff, yoff);
showPopuWindow();
}
@Override
public void showAsDropDown(View anchor, int xoff, int yoff, int gravity) {
// TODO Auto-generated method stub
super.showAsDropDown(anchor, xoff, yoff, gravity);
showPopuWindow();
}
@Override
public void showAtLocation(View parent, int gravity, int x, int y) {
// TODO Auto-generated method stub
super.showAtLocation(parent, gravity, x, y);
showPopuWindow();
}
private void showPopuWindow(){
setWindowBackgroundAlpha(0.8f);
if (mShowingListener!=null) {
mShowingListener.onShowing();
}
}
@Override
public void setOnDismissListener(OnDismissListener onDismissListener) {
setWindowBackgroundAlpha(1f);
super.setOnDismissListener(onDismissListener);
}
/**
* 控制窗口背景的不透明度 *
*/
private void setWindowBackgroundAlpha(float alpha) {
Window window = ((Activity) context).getWindow();
WindowManager.LayoutParams layoutParams = window.getAttributes();
layoutParams.alpha = alpha;
window.setAttributes(layoutParams);
}
public interface ShowingListener {
public void onShowing();
}
private MyInput.ShowingListener mShowingListener;
public void setShowingListener(MyInput.ShowingListener showingListener) {
this.mShowingListener = showingListener;
}
/*
* 获取屏幕的宽高
*/
public int[] getScreenSize(){
int[] size=new int[2];
DisplayMetrics dm=new DisplayMetrics();
WindowManager wm=(WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
wm.getDefaultDisplay().getMetrics(dm);
size[0]=dm.widthPixels;
size[1]=dm.heightPixels;
return size;
}
}

    

4.2activity里面的动态写popupwindow
shipin_pinglun.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//dibu.setVisibility(dibu.GONE);
        if (myInput==null){
myInput=new MyInput(SurfaceViewActivity.this);

myInput.setShowingListener(new MyInput.ShowingListener() {
@Override
public void onShowing() {
}
});
myInput.setOnDismissListener(new PopupWindow.OnDismissListener() {
@Override
public void onDismiss() {
WindowManager.LayoutParams lp=getWindow().getAttributes();
lp.alpha = 1f;
getWindow().setAttributes(lp);
dibu.setVisibility(dibu.VISIBLE);
}
});
}
myInput.showAtLocation(findViewById(android.R.id.content),Gravity.BOTTOM,0,0);
}
});


05-11 14:50