【问题标题】:How to create a circle button in the right bottom corner on Android 5+?如何在Android 5+的右下角创建一个圆形按钮?
【发布时间】:2015-09-07 04:15:36
【问题描述】:

是否有任何标准工具或现有库可以像在 Gmail 应用程序上一样创建圆形按钮?

【问题讨论】:

标签: android user-interface


【解决方案1】:

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" 

到你的布局文件。

  1. 您也可以通过fab_type xml属性设置按钮类型(普通或迷你)(默认为普通):

fab:fab_type="mini"

或

fab.setType(FloatingActionButton.TYPE_MINI);

【讨论】:

    【解决方案2】:

    在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 的库,例如

    【讨论】:

      【解决方案3】:

      是的,新的Design Support Library 提供了浮动操作按钮的默认实现here。

      为了访问新的 FAB 类,您需要将此依赖项添加到您的 gradle 构建文件中。

      compile 'com.android.support:design:22.2.0'
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-05-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-01-13
        • 2020-10-27
        • 1970-01-01
        • 2018-07-23
        相关资源
        最近更新 更多