android悬浮按钮的使用

摘要:
首先准备一张图片,并将其保存在activity_Undermain.xml中的drawbable下˂?

首先准备一张图片保存在drawable下

在activity_main.xml下

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/draw_lay"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        >
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolBar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            />
        <!--下面是悬浮按钮-->
        <android.support.design.widget.FloatingActionButton
            android:id="@+id/fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|end"
            android:layout_margin="16dp"
            android:src="@drawable/done"
            app:elevation="8dp"/><!--设置高度值-->
    </FrameLayout>
    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:menu="@menu/navmenu"
        app:headerLayout="@layout/navhead"/>

</android.support.v4.widget.DrawerLayout>

在MainActivity中添加响应事件

在下面代码中使用了SnackBar,这个控件可以弹出一个可与用户交互的消息,创建SnackBar三个参数分别是:view,内容,时长

 FloatingActionButton fab=(FloatingActionButton)findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Snackbar.make(v,"你点击了悬浮按钮",Snackbar.LENGTH_SHORT).setAction("Undo",new View.OnClickListener(){
                    @Override
                    public void onClick(View v){
                        Toast.makeText(MainActivity.this,"你点击了悬浮按钮中的Undo按钮",Toast.LENGTH_SHORT).show();
                    }

                }).show();

android悬浮按钮的使用第1张

在这种情况下SnackBar弹出的内容就会自动挡住悬浮按钮,此时我们将xml布局中的FrameLayout改为<android.support.design.widget.CoordinatorLayout

这是Material Design中提供一种布局在平常情况下与FrameLayout差异不大,但是他可以监控所有子控件的事件,然后为我们做出合理的相应

免责声明:文章转载自《android悬浮按钮的使用》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇使用WebDAV实现Office文档在线编辑c#开发_Dev的关于XtraGrid的使用(GridControl小结)下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

layerui如何隐藏按钮?

https://www.layui.com/doc/modules/layer.html#btn 建议把 btn: ['取消'],btnAlign: 'c',yes: function (index) { layer.close(index); //layer.close(layer.index); }这一段配置去除即可,就不会出现按钮了,...

ZK框架笔记5、事件

        事件是org.zkoss.zk.ui.event.Event类,它通知应用程序发生了什么事情。每一种类型的事件都由一个特定的类来表示。         要响应一个事件,应用程序必须为事件注册一个或更多事件监听器。有3种方式可以为一个组件事件监听器。   (1)一般制定onXXX事件监听器为组件的属性,作为属性定义的事件监听器。 &...

javascript中的后退和刷新

<input type=button value=刷新 onclick="window.location.reload()"><input type=button value=前进 onclick="window.history.go(1)"><input type=button value=后退 onclick="window...

Ubuntu上交叉编译valgrind for Android 4.0.4的过程与注意事项

编译环境:Ubuntu x86_64(Linux root 2.6.32-45-generic #101-Ubuntu SMP Mon Dec 3 15:39:38 UTC 2012 x86_64 GNU/Linux) 运行环境:Android 4.0.4 (Linux kernel 3.0.21 OMAP4460) 一、下载NDK9和valgrind...

部署自己的聊天系统 DuckChat(鸭信)

之前在找一款能自己部署的聊天系统,要求含有手机端APP,最好部署过程能简单点的。看了几款稍嫌麻烦,有的还没有app。今天无意间发现了这款DuckChat,开源免费,有手机APP,部署非常简单。直接上传到你的web根目录然后安装就行了。 演示地址(含Web体验) http://gaga.akaxin.com Android客户端 Android下...

Android学习系列(3)App自动更新之自定义进度视图和内部存储

友好的视觉感知和稳定的不出错表现,来自于我们追求美感和考虑的全面性,博客园从技术的角度,一直我都很欣赏。这篇文章是android开发人员的必备知识,是我特别为大家整理和总结的,不求完美,但是有用。  这一篇是对上一篇《Android学习系列(2)--App自动更新之通知栏下载》的补充,因此只是以点为要,点到为止。1.内部存储    出于考虑到用户可能禁掉了...