80,351
社区成员
发帖
与我相关
我的任务
分享
mPop=new CustomPopupWindow(this);
mPop.setOnItemClickListener(this);
imm = (InputMethodManager) getSystemService(Service.INPUT_METHOD_SERVICE);
findViewById(R.id.id_start).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//设置PopupWindow中的位置
mPop.showAtLocation(PopupWin.this.findViewById(R.id.main), Gravity.BOTTOM|Gravity.CENTER_HORIZONTAL, 0,0);
}
});
View layout;
private void writeDelivery() {
layout = getLayoutInflater().inflate(R.layout.playvideo_popsned,null);
EditText inputCmpny = (EditText) layout.findViewById(R.id.movpopwin_edit);
int H;
H = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
layout.measure(0, H);
H = layout.getMeasuredHeight();
// pop = new PopupWindow(layout, DeviceUtil.getScreenPixels(this).getWidth(), H);
pop = new PopupWindow(layout, ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT,true);
ColorDrawable cd = new ColorDrawable(-0000);
pop.setBackgroundDrawable(cd);
pop.update();
pop.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
pop.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
pop.setTouchable(true); // 设置popupwindow可点击
pop.setOutsideTouchable(true); // 设置popupwindow外部可点击
pop.setFocusable(true); // 获取焦点
pop.showAtLocation(layout, Gravity.BOTTOM, 0, 0);
pop.setTouchInterceptor(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
/**** 如果点击了popupwindow的外部,popupwindow也会消失 ****/
if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
EditText movpoedit = (EditText) layout.findViewById(R.id.win_edit);
imm.hideSoftInputFromWindow(movpoedit.getWindowToken(), 0);
pop.dismiss();
return true;
}
return false;
}
});
}
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff" >
<LinearLayout
android:id="@+id/layout_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="2px" >
<EditText
android:id="@+id/win_edit"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginLeft="16dp"
android:textColor="#7f8c8d"
android:layout_weight="1"
android:background="#ffffff"
android:hint=" 评论"
android:textSize="15sp"
android:singleLine="true" />
</LinearLayout>
</FrameLayout>