final PopupWindow pop = new PopupWindow(LayoutParams.WRAP_CONTENT,LayoutParams.MATCH_PARENT); ListView listView = new ListView(this); listView.setBackgroundColor(Color.WHITE); ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, type1); listView.setAdapter(adapter); pop.setContentView(listView); pop.setOutsideTouchable(true); pop.setFocusable(true); // listview.requestFocus(); pop.update(); pop.setBackgroundDrawable(new BitmapDrawable()); pop.showAsDropDown(view); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { pop.dismiss(); } });
其中包括了点击其他部分dismiss,点击listview 的item 才能取消,点击textview
时间: 2024-10-12 23:23:11