PopupWindow的使用
生活随笔
收集整理的這篇文章主要介紹了
PopupWindow的使用
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
想要彈出內容就可以考慮使用懸浮窗
布局 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:id="@+id/rl_root"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"tools:context=".LoginActivity" ><com.handmark.pulltorefresh.library.PullToRefreshListViewandroid:id="@+id/lv_list"android:layout_width="match_parent"android:layout_height="match_parent"android:layout_weight="1"android:background="#fff" /><Viewandroid:id="@+id/viewHolder"android:layout_width="match_parent"android:layout_height="53dp"android:visibility="gone" /> </LinearLayout>代碼
lv_list.setOnItemLongClickListener(new OnItemLongClickListener() {@Overridepublic boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {Toast.makeText(getApplicationContext(), "長按", 0).show();//開啟編輯模式startEditModel();if (position > 0) {position -= 1;}adapter.toggleSelect(view, position);return true;}});}private boolean isEditModel;private int seletedCount;/*** 開啟編輯模式*/private void startEditModel() {//listview需要刷新isEditModel = true;adapter.notifyDataSetChanged();//修改actionbaruploadMenuItem.setVisible(false);downloadMenuItem.setVisible(false);moreMenuItem.setVisible(false);selectMenuItem.setVisible(true);actionBar.setDisplayHomeAsUpEnabled(true);actionBar.setTitle(String.format("已選定%d個", seletedCount));//顯示底部的popupwindows //當在最 底部時會覆蓋條目,可以在下面弄個view,讓他顯示showBottomPopupWindow();//listview上移viewHolder.setVisibility(0);}/*** 結束編輯模式*/private void stopEditModel() {//listview需要刷新isEditModel = false;adapter.notifyDataSetChanged();//修改actionbaruploadMenuItem.setVisible(true);downloadMenuItem.setVisible(true);moreMenuItem.setVisible(true);selectMenuItem.setVisible(false);actionBar.setTitle("黑馬網盤");//返回按鈕的處理if ("/".equals(curPath)) {actionBar.setDisplayHomeAsUpEnabled(false);}//隱藏popupwindowsbottomPopupWindow.dismiss();//listview還原viewHolder.setVisibility(8);//還原entryWrapper的選中狀態for (EntryWrapper entryWrapper : contents) {entryWrapper.isCheck = false;}seletedCount = 0;}private void showBottomPopupWindow() {if (bottomPopupWindow == null) {View contentView = View.inflate(MainActivity.this, R.layout.bottom_edit_pop, null);int width = ViewGroup.LayoutParams.FILL_PARENT;int height = ViewGroup.LayoutParams.WRAP_CONTENT;bottomPopupWindow = new PopupWindow(contentView, width, height);contentView.findViewById(R.id.DeleteBtn).setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {List<EntryWrapper> selectedEntryWrappers = new ArrayList<EntryWrapper>();for (EntryWrapper info : contents) {if (info.isCheck) {selectedEntryWrappers.add(info);}}StringBuffer sb = new StringBuffer();//遍歷輸出for (EntryWrapper entryWrapper : selectedEntryWrappers) {sb.append(entryWrapper.entry.fileName()).append(" ");}System.out.println(sb.toString());}});}bottomPopupWindow.showAtLocation(rl_root, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);}
轉載于:https://www.cnblogs.com/sixrain/p/5276612.html
總結
以上是生活随笔為你收集整理的PopupWindow的使用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: JS-DOM Element方法和属性
- 下一篇: ajax 请求超过了5s 还没有返回