zoukankan      html  css  js  c++  java
  • android悬浮按钮的使用

    首先准备一张图片保存在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();

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

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

  • 相关阅读:
    【Silverlight】Bing Maps学习系列(八):使用Bing Maps Silverlight Control加载自己部署的Google Maps
    Visual Studio 2010在简洁中强调团队合作
    【Silverlight】Bing Maps学习系列(九):自定义功能导航条(Custom NavigationBar)
    Flash OBJECT 和 EMBED 标签
    SWFObject 的原站提供的使用说明
    一篇清楚阐述 JAvaScript 传递数据 到 Flash 的文章
    Flare 的 Edge边上加 Label
    借助 SWFObject 实现利用JavaScript嵌入 Flash
    3种基本的Flash/Javascript通信方式 (转)
    passing data from HTML to Flash
  • 原文地址:https://www.cnblogs.com/837634902why/p/10628135.html
Copyright © 2011-2022 走看看