4.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.PullToRefreshListView
android:id="@+id/lv_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#fff" />
<View
android:id="@+id/viewHolder"
android:layout_width="match_parent"
android:layout_height="53dp"
android:visibility="gone" />
</LinearLayout>
代码
lv_list.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public 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();
//修改actionbar
uploadMenuItem.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();
//修改actionbar
uploadMenuItem.setVisible(true);
downloadMenuItem.setVisible(true);
moreMenuItem.setVisible(true);
selectMenuItem.setVisible(false);
actionBar.setTitle("黑马网盘");
//返回按钮的处理
if ("/".equals(curPath)) {
actionBar.setDisplayHomeAsUpEnabled(false);
}
//隐藏popupwindows
bottomPopupWindow.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() {
@Override
public 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);
}
4.PopupWindow的更多相关文章
- Android PopupWindow Dialog 关于 is your activity running 崩溃详解
Android PopupWindow Dialog 关于 is your activity running 崩溃详解 [TOC] 起因 对于 PopupWindow Dialog 需要 Activi ...
- Android popupwindow使用心得(一)
最近项目中好多地方用到popupwindow,感觉这个控件还是非常重要的.所以把使用心得总结下,废话不多说,直接上代码. public class MainActivity extends Activ ...
- 不得不吐槽的Android PopupWindow的几个痛点(实现带箭头的上下文菜单遇到的坑)
说到PopupWindow,我个人感觉是又爱又恨,没有深入使用之前总觉得这个东西应该很简单,很好用,但是真正使用PopupWindow实现一些效果的时候总会遇到一些问题,但是即便是人家的api有问题, ...
- 仿QQ空间根据位置弹出PopupWindow显示更多操作效果
我们打开QQ空间的时候有个箭头按钮点击之后弹出PopupWindow会根据位置的变化显示在箭头的上方还是下方,比普通的PopupWindow弹在屏幕中间显示好看的多. 先看QQ空间效果图: ...
- 自定义PopupWindow
PopupWindow,一个弹出窗口控件,可以用来显示任意View,而且会浮动在当前activity的顶部 自定义PopupWindow. 1.extends PopupWindow 2.构造方法中可 ...
- PopupWindow 使用
昨天马失前蹄,为了做一个小键盘,耽误了两个小时,记录一下心路历程 1.关于需求与选择 需求: 点击一个按钮,弹出一个小键盘(类似于输入法键盘) 选择: (1)方案一:KeyboardView 这是百度 ...
- popupwindow的基本使用以及基本动画效果
1.创建一个popupwindow view的布局文件自己写一个就好了,这里就不说了 View view= LayoutInflater.from(context).inflate(R.layout. ...
- Android -- PopupWindow(其中嵌套ListView 可以被点击)
1. 效果图
- Android开发学习之路-PopupWindow和仿QQ左滑删除
这周作业,要做一个类似QQ的左滑删除效果的ListView,因为不想给每个item都放一个按钮,所以决定用PopupWindow,这里记录一下 先放一下效果图: 先说明一下这里面的问题: ①没有做到像 ...
- android标题栏上面弹出提示框(二) PopupWindow实现,带动画效果
需求:上次用TextView写了一个从标题栏下面弹出的提示框.android标题栏下面弹出提示框(一) TextView实现,带动画效果, 总在找事情做的产品经理又提出了奇葩的需求.之前在通知栏显示 ...
随机推荐
- CocoStudio基础教程(5)使用CocoStudio场景编辑器关联组件
1.概述 我们有了UI交互.有了动画人物.有了物理模拟,还差最后一步——将这些元素融合起来.这就要用到cocoStudio中的场景编辑器了.这次我们要将先前我们做过的所有东西都放到一个场景中去.这项工 ...
- /run/systemd/private: No such file or directory
今天执行consul脚本的时候报错 /run/systemd/private: No such file or directory reboot -f 重启电脑private文件就出现了.
- HLG2081分苹果
苹果 Time Limit: 1000 MS Memory Limit: 32768 K Total Submit: 39(24 users) Total Accepted: 29(22 users) ...
- windows下的C/C++精确计时
由于我要测试线性筛法的速度,用上了C/C++精确计时.此时传统的clock()方法不够用了,我们需要另一种测量的办法,即CPUTicks/CPUFreq.如何实现呢? #include <win ...
- CSS3.0盒模型display:-webkit-box;的使用
box-flex是css3新添加的盒子模型属性,它的出现可以解决我们通过N多结构.css实现的布局方式.经典 的一个布局应用就是布局的垂直等高.水平均分.按比例划分. 目前box-flex属性还没 ...
- jekyll中文乱码问题
一般编写都是采用utf-8的吧,但是在windows下安装的jekyll,默认是以GBK编码的方式去读取咱们编写的文件,如此便乱码了. 要解决此问题,总不至于要写GBK编码的文件吧,毕竟这个编码不怎么 ...
- js 实现图片预加载 (js操作 Image对象属性complete ,事件onload 异步加载图片)
通过js操纵DOM很多情况下都是为了实现和当前页html元素的异步载入,我谈谈对Image对象的一些认识.看个例子:<input type="button" name=&qu ...
- CSS用Id选择器在本页写样式
<title>静夜思</title><style type="text/css">#red{color:#ff0000; font-weight ...
- lambda 表达式
C++0x 的语法还是比较简单.下面通过几个例子来介绍下. 先是通过 std::for_each 演示一个简单的例子: ? std::for_each 和 lambda 1 2 3 4 5 6 7 8 ...
- Android Studio中的Module,Facet
详细内容请参看 http://www.jetbrains.com/idea/webhelp/facet.html 以及 http://www.jetbrains.com/idea/webhelp/an ...