java Android 浮动操作按钮 API 19 (KitKat)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26928976/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 10:53:27  来源:igfitidea点击:

Android Floating Action Button API 19 (KitKat)

javaandroidandroid-layoutandroid-support-library

提问by falvojr

I need to implement a floating action button, according to Google Design Guidelines, on my android application with API level 19.

根据Google 设计指南,我需要在 API 级别为 19 的 android 应用程序上实现一个浮动操作按钮。

However, I would know if some native support library (like v4, v7, v13) to help me build this component without the need for external dependencies.

但是,我想知道是否有一些本机支持库(如 v4、v7、v13)可以帮助我构建此组件而无需外部依赖项。

采纳答案by falvojr

Recently Google has released a new support library based on Material Design Guideline. The Codepath details the same components in this post.

最近谷歌发布了一个新的基于Material Design Guideline 的支持库。该代码路径详细介绍了相同的组件这篇文章

The library can be already used with Gradle adding the following line in build.gradle:

该库已经可以与 Gradle 一起使用,在 build.gradle 中添加以下行:

dependencies {
    ...
    compile 'com.android.support:design:25.3.1'
}

This is a simple example of usage:

这是一个简单的用法示例:

<android.support.design.widget.FloatingActionButton
      android:id="@+id/fab"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:src="@drawable/ic_add"
      android:layout_gravity="bottom|end" />

See more FloatingActionButton example with Support Library.

使用支持库查看更多FloatingActionButton 示例

回答by MrEngineer13

I would know if some native support library (like v4, v7, v13) to help me build this component without the need for external dependencies.

我想知道是否有一些本机支持库(如 v4、v7、v13)可以帮助我构建这个组件而无需外部依赖。

No there aren't any support library floating action buttons (FAB). IMHO, it's a horrible decision to not include all of the material related widgets in the support library. In this videoChet Haase and Adam Powell basically say that the FAB is very easy to reproduce so they're not going to include it in any support library. So instead of Google creating one set of the material widgets to be used by millions of developers they would rather millions of developers create millions of different implementation of these widgets. </rant>

不,没有任何支持库浮动操作按钮 (FAB)。恕我直言,在支持库中不包含所有与材料相关的小部件是一个可怕的决定。在这个视频中,Chet Haase 和 Adam Powell 基本上说 FAB 很容易复制,所以他们不会将它包含在任何支持库中。因此,Google 与其创建一组材料小部件以供数百万开发人员使用,不如让数百万开发人员创建这些小部件的数百万种不同实现。 </rant>

You can just make your own FAB by extending the Viewclass. Here is an examplefrom Github of a FAB that does not use any outside libraries.

您可以通过扩展View类来制作自己的 FAB 。这是来自 Github 的一个不使用任何外部库的 FAB示例