Android BottomSheet:便捷易用的底部滑出面板(1)
Android BottomSheet:便捷易用的底部滑出面板(1)
Android BottomSheet是github上的一个第三方开源项目,其主页:https://github.com/Flipboard/bottomsheet
BottomSheet提供了简洁易用的从底部滑出的面板。现在的APP开发,经常需要从底部滑出某些面板提供给用户操作入口,比如最常见的分享,底部滑出一个面板,然后会罗列出多种分享入口,供用户选择。
使用BottomSheet,需要首先在自己的模块build.gradle文件中加入下面代码:
repositories {
jcenter()
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.flipboard:bottomsheet-core:1.5.1'
compile 'com.flipboard:bottomsheet-commons:1.5.1'
}
如图:
接下来就可以使用BottomSheet。先写布局。用BottomSheet提供的BottomSheetLayout把自己整个页面包裹起来:
<?xml version="1.0" encoding="utf-8"?>
<com.flipboard.bottomsheet.BottomSheetLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/bottomsheet"
android:layout_width="match_parent"
android:layout_height="match_parent"> <LinearLayout
android:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp"> <EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="zhang phil @ csdn"
android:id="@+id/editText" /> <Button
android:id="@+id/share_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:text="分享" /> </LinearLayout> </com.flipboard.bottomsheet.BottomSheetLayout>
上层Java代码:
package zhangphil.demo; import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.support.v4.content.res.ResourcesCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText; import com.flipboard.bottomsheet.BottomSheetLayout;
import com.flipboard.bottomsheet.commons.IntentPickerSheetView; import java.util.Collections;
import java.util.Comparator; public class MainActivity extends AppCompatActivity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); final BottomSheetLayout bottomSheetLayout = (BottomSheetLayout) findViewById(R.id.bottomsheet);
final EditText shareText = (EditText) findViewById(R.id.editText); Button shareButton = (Button) findViewById(R.id.share_button);
shareButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// 隐藏软键盘
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(shareText.getWindowToken(), 0); final Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, shareText.getText() + "");
shareIntent.setType("text/plain"); IntentPickerSheetView intentPickerSheet = new IntentPickerSheetView(getApplication(), shareIntent, "分享到...", new IntentPickerSheetView.OnIntentPickedListener() {
@Override
public void onIntentPicked(IntentPickerSheetView.ActivityInfo activityInfo) {
bottomSheetLayout.dismissSheet();
startActivity(activityInfo.getConcreteIntent(shareIntent));
}
}); // 过滤到像系统蓝牙这样的分享模式(可以过滤掉也可以不用过滤)
/*
intentPickerSheet.setFilter(new IntentPickerSheetView.Filter() {
@Override
public boolean include(IntentPickerSheetView.ActivityInfo info) {
return !info.componentName.getPackageName().startsWith("com.android");
}
});
*/ // 排序分享模块
intentPickerSheet.setSortMethod(new Comparator<IntentPickerSheetView.ActivityInfo>() {
@Override
public int compare(IntentPickerSheetView.ActivityInfo lhs, IntentPickerSheetView.ActivityInfo rhs) {
return rhs.label.compareTo(lhs.label);
}
}); // 增加一个自定义的分享选择方式(可选)
Drawable customDrawable = ResourcesCompat.getDrawable(getResources(), R.mipmap.ic_launcher, null);
IntentPickerSheetView.ActivityInfo customInfo = new IntentPickerSheetView.ActivityInfo(customDrawable, "zhang phil custom", getApplicationContext(), MainActivity.class);
intentPickerSheet.setMixins(Collections.singletonList(customInfo)); bottomSheetLayout.showWithSheetView(intentPickerSheet);
}
});
}
}
分享的button按钮触发弹出分享面板,分享面板可以向上拖曳铺满。
代码运行初始化:
点击分享按钮弹出分享面板:
拖曳分享面板向上铺满窗口:
附录文章:
1,《Android自底部平滑向上滑出面板的AndroidSlidingUpPanel》链接地址:http://blog.csdn.net/zhangphil/article/details/51444509
2,《Android音乐、视频类APP常用控件:DraggablePanel(1)》链接地址:http://blog.csdn.net/zhangphil/article/details/51566860
3,《Android音乐、视频类APP常用控件:DraggablePanel(2)》链接地址:http://blog.csdn.net/zhangphil/article/details/51578665
Android BottomSheet:便捷易用的底部滑出面板(1)的更多相关文章
- AndroidSweetSheet:从底部弹出面板(1)
AndroidSweetSheet:从底部弹出面板(1) AndroidSweetSheet又是一个从底部弹出面板的开源项目.我在以前写的文章中介绍了不少这些项目,见附录文章5,6,7,8.现在 ...
- 一款jQuery打造的滚动条在底部滑出信息提示层
一款jQuery打造的滚动条在底部滑出信息提示层, 当滚动鼠标滚轮,或者滚动条往下拉的时候,在右下角,弹出一个信息提示框. 有一点仿的是一个插件工具,就是网页中大家都长用到的友荐. 这款特效算一款简单 ...
- Android BottomSheet:底部弹出Fragment面板(4)
Android BottomSheet:底部弹出Fragment面板(4) BottomSheet不仅可以弹出轻量级的定制好的面板(见附录文章5,6,7),还可以弹出"重"的 ...
- Android BottomSheet:List列表或Grid网格展示(3)
Android BottomSheet:List列表或Grid网格展示(3) BottomSheet可以显示多种样式的底部弹出面板风格,比如常见的List列表样式或者Grid网格样式,以一个例子 ...
- Android BottomSheet:以选取图片为例(2)
Android BottomSheet:以选取图片为例(2) 附录文章5简单介绍了常见的分享面板在BottomSheet中的具体应用.本文再以常见的选取图片为例写一个例子. 布局文件: < ...
- Android Demo---实现从底部弹出窗口
在前面的博文中,小编简单的介绍了如何制作圆角的按钮以及圆角的图片,伴着键盘和手指之间的舞步,迎来新的问题,不知道小伙伴有没有这样的经历,以App为例,点击头像的时候,会从底部弹出一个窗口,有从相册中选 ...
- jquery定时滑出可最小化的底部提示层
效果预览:http://keleyi.com/keleyi/phtml/jqtexiao/index.htm当打开页面或者刷新页面后等待两秒钟,会在底部滑出可最小化的提示层.滑出层半透明,可关闭再现. ...
- android Activity实现底部滑动弹出窗口及源码下载地址
在做微信.微博.qq等分享时,一般是点击分享按钮后会从底部弹出滑动窗口,然后选择要分享的社交平台进行分享.今日头条.腾讯新闻等内容App的评论也是从底部滑动弹出输入窗口,进行评论输入的.本篇文章就讲讲 ...
- android去掉滑动到顶部和底部的阴影
android去掉滑动到顶部和底部的阴影 <ListView android:id="@+id/listView" android:layout_width="ma ...
随机推荐
- 为什么JavaWeb项目要分层
首先让我们坐着时光机回到n年前的web开发.那个时候最早都是静态的html页面,后来有了数据库,有了所谓的动态页面,然后程序猿在编码的时候,会把所有的代码都写在页面上,包括数据库连接,包括事务控制,接 ...
- bzoj 1707: [Usaco2007 Nov]tanning分配防晒霜【贪心||最大流(?)】
洛谷上能过的最大流bzoj上T了--但是贪心做法明明在洛谷上比最大流要慢啊--如果是最大流的话就是裸题了吧 说一下贪心,就按照防晒霜排序,然后对每一个防晒霜选一头可以使用的且r最小的牛 就,没了. 贪 ...
- Vigenère密码 2012年NOIP全国联赛提高组(字符串模拟)
P1079 Vigenère 密码 题目描述 16 世纪法国外交家 Blaise de Vigenère 设计了一种多表密码加密算法――Vigenère 密 码.Vigenère 密码的加密解密算法简 ...
- Linux 搭建Discuz论坛
title: Linux 搭建Discuz论坛 Welcome to Fofade's Blog! 这里是Linux 搭建论坛的一些命令记录 命令摘记: 下载文件:Discuz 安装环境:PHP Ap ...
- Ajax 知识点总结
1.AJAX的优缺点都有什么? 最大的一点是页面无刷新,用户的体验非常好.使用异步方式与服务器通信,具有更加迅速的响应能力.可以把以前一些服务器负担的工作转嫁到客户端,利用客户端闲置的能力来处理,减轻 ...
- 【转】MySQL常见的运算符及使用
转自:http://www.linuxidc.com/Linux/2016-03/129672.htm MySQL中有4类运算符,它们是: 算术运算符 比较运算符 逻辑运算符 位操作运算符 算术操作符 ...
- [译]libcurl_tutorial
Handle the Easy libcurl To use the easy interface, you must first create yourself an easy handle. Yo ...
- CF822C Hacker, pack your bags!
思路: 对于一个区间[l, r],只需枚举所有满足r' < l并且二者duration之和为x的区间[l', r'],寻找其中二者cost之和最小的即可.于是可以开一个数组a[],a[i]表示所 ...
- 全志A33平台编译linux(分色排版)V1.1
全志A33平台编译linux 大文实验室/大文哥 壹捌陆捌零陆捌捌陆捌贰 21504965 AT qq.com 完成时间:2017/12/13 10:41 版本:V1.1 (一)解压缩lichee备用 ...
- 如何利用sql注入进行爆库
SQL注入能做什么 在<SQL注入基础>一文介绍了SQL注入的基本原理和实验方法,那接下来就要问一下,SQL注入到底能什么? 估计很多朋友会这样认为:利用SQL注入最多只能获取当前表中的所 ...