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)的更多相关文章

  1. AndroidSweetSheet:从底部弹出面板(1)

     AndroidSweetSheet:从底部弹出面板(1) AndroidSweetSheet又是一个从底部弹出面板的开源项目.我在以前写的文章中介绍了不少这些项目,见附录文章5,6,7,8.现在 ...

  2. 一款jQuery打造的滚动条在底部滑出信息提示层

    一款jQuery打造的滚动条在底部滑出信息提示层, 当滚动鼠标滚轮,或者滚动条往下拉的时候,在右下角,弹出一个信息提示框. 有一点仿的是一个插件工具,就是网页中大家都长用到的友荐. 这款特效算一款简单 ...

  3. Android BottomSheet:底部弹出Fragment面板(4)

     Android BottomSheet:底部弹出Fragment面板(4) BottomSheet不仅可以弹出轻量级的定制好的面板(见附录文章5,6,7),还可以弹出"重"的 ...

  4. Android BottomSheet:List列表或Grid网格展示(3)

     Android BottomSheet:List列表或Grid网格展示(3) BottomSheet可以显示多种样式的底部弹出面板风格,比如常见的List列表样式或者Grid网格样式,以一个例子 ...

  5. Android BottomSheet:以选取图片为例(2)

     Android BottomSheet:以选取图片为例(2) 附录文章5简单介绍了常见的分享面板在BottomSheet中的具体应用.本文再以常见的选取图片为例写一个例子. 布局文件: < ...

  6. Android Demo---实现从底部弹出窗口

    在前面的博文中,小编简单的介绍了如何制作圆角的按钮以及圆角的图片,伴着键盘和手指之间的舞步,迎来新的问题,不知道小伙伴有没有这样的经历,以App为例,点击头像的时候,会从底部弹出一个窗口,有从相册中选 ...

  7. jquery定时滑出可最小化的底部提示层

    效果预览:http://keleyi.com/keleyi/phtml/jqtexiao/index.htm当打开页面或者刷新页面后等待两秒钟,会在底部滑出可最小化的提示层.滑出层半透明,可关闭再现. ...

  8. android Activity实现底部滑动弹出窗口及源码下载地址

    在做微信.微博.qq等分享时,一般是点击分享按钮后会从底部弹出滑动窗口,然后选择要分享的社交平台进行分享.今日头条.腾讯新闻等内容App的评论也是从底部滑动弹出输入窗口,进行评论输入的.本篇文章就讲讲 ...

  9. android去掉滑动到顶部和底部的阴影

    android去掉滑动到顶部和底部的阴影 <ListView android:id="@+id/listView" android:layout_width="ma ...

随机推荐

  1. Unity使用外部版本控制

    Using External Version Control Systems with Unity Unity offers an Asset Server add-on product for ea ...

  2. bzoj 1641: [Usaco2007 Nov]Cow Hurdles 奶牛跨栏【Floyd】

    先跑一遍取max版的Floyd,直接用数组回答询问即可 #include<iostream> #include<cstdio> using namespace std; con ...

  3. bzoj 1634: [Usaco2007 Jan]Protecting the Flowers 护花【贪心】

    因为交换相邻两头牛对其他牛没有影响,所以可以通过交换相邻两头来使答案变小.按照a.t*b.f排降序,模拟着计算答案 #include<iostream> #include<cstdi ...

  4. 读懂mysql慢查询日志

    我们来看一下如何去读懂这些慢查询日志.在跟踪慢查询日志之前,首先你得保证最少发生过一次慢查询.如果你没有可以自己制造一个:root@server# mysql -e 'SELECT SLEEP(8); ...

  5. Android 性能优化(4)Optimizing Layout Hierarchies:用Hierarchy Viewer和Layoutopt优化布局

    Optimizing Layout Hierarchies This lesson teaches you to Inspect Your Layout Revise Your Layout Use ...

  6. 在dataGridView空间中添加数据

    //查询信息sql语句 string sql = "select studentName,addres from student"; SqlDataAdapter adapter ...

  7. MVC之参数验证(一)

    ASP.NET MVC采用Model绑定为目标Action生成了相应的参数列表,但是在真正执行目标Action方法之前,还需要对绑定的参数实施验证以确保其数据的准确性.总地来说,我们可以采用Syste ...

  8. Paxos,Raft,Zab一致性协议-Raft篇

    Raft是一个一致性算法,旨在易于理解.它提供了Paxos的容错和性能.不同之处在于它被分解为相对独立的子问题,它清楚地解决了实际系统所需的所有主要部分.我们希望Raft能够为更广泛的受众提供共识,并 ...

  9. 可以在一个html的文件当中读取另一个html文件的内容

    1.IFrame引入,看看下面的代码 <IFRAME NAME="content_frame" width=100% height=30 marginwidth=0 marg ...

  10. delphi 字符串处理中的怪异现象与处理

    1, 怪异现象:字符串相加操作不正常! 以上代码,明显输出字符串应含有后缀“.jpg”,但实际输出却不含后缀(如下),字符串加法操作似乎不起作用了! 采用showMessage进行输出,看看结果如何? ...