【发布时间】:2015-09-07 04:15:36
【问题描述】:
是否有任何标准工具或现有库可以像在 Gmail 应用程序上一样创建圆形按钮?
【问题讨论】:
是否有任何标准工具或现有库可以像在 Gmail 应用程序上一样创建圆形按钮?
【问题讨论】:
1.首先重要的是使用Android Studio
2.将依赖项添加到您的 build.gradle:
dependencies {
compile 'com.melnykov:floatingactionbutton:1.3.0'
}
3。创建布局
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.melnykov.fab.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_margin="16dp"
android:src="@drawable/ic_action_content_new"
fab:fab_colorNormal="@color/primary"
fab:fab_colorPressed="@color/primary_pressed"
fab:fab_colorRipple="@color/ripple" />
4.添加命名空间
xmlns:fab="http://schemas.android.com/apk/res-auto"
到你的布局文件。
fab:fab_type="mini"
或
fab.setType(FloatingActionButton.TYPE_MINI);
【讨论】:
在android support design support library中提供的一个小部件是Floating Action Button,它通常被添加在右下角(但不必只在那里使用)
浮动操作按钮是表示主要操作的圆形按钮 在您的界面上。设计库的 FloatingActionButton 为您提供 一个一致的实现,默认情况下使用 colorAccent 来自您的主题。
要在 build.gradle 文件中获取 android 设计支持库,请添加以下内容:
compile 'com.android.support:design:22.2.0'
在你的布局文件中”
<RelativeLayout
...
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.design.widget.FloatingActionButton
android:id="@+id/myFAB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_anchor="@id/appbar"
app:layout_anchorGravity="bottom|right|end"
android:src="@drawable/ic_discuss"
android:layout_margin="10dp"
android:clickable="true"/>
</RelativeLayout>
android设计支持库详情here
还有许多其他提供 FAB 的库,例如
【讨论】:
是的,新的Design Support Library 提供了浮动操作按钮的默认实现here。
为了访问新的 FAB 类,您需要将此依赖项添加到您的 gradle 构建文件中。
compile 'com.android.support:design:22.2.0'
【讨论】: