Android使用Material Design实现悬浮按钮

前言

​ 本文是对《Android第一行代码》第十二章《最佳UI体验——Material Design实战》中关于悬浮按钮实现的学习和记录,主要内容包括——

  • FloatingActionButton控件
  • Snackbar控件
  • CoordinatorLayout布局

其实关于悬浮按钮的实现十分简单,Design Support库中做了大量的封装,只需要运用以上3个基础控件就可以完成一个最简单的悬浮球样式了。实际上,目前关于Android悬浮球的实现方案挺多的,网上可以找到很多酷炫的悬浮球实现方式。

悬浮按钮

立面设计是Material Design设计中一个非常重要的思想,在官方的示例中,最简单且具有代表性的立面设计就是悬浮按钮了。本节是对悬浮按钮以及其交互提示的学习和总结。

  • FloatingActionButton控件

FloatingActionButton可以直接实现一个悬浮球的效果,我们修改activity_main.xml中的代码,如下:

<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout
    ...
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:background="?attr/colorPrimary"
            android:layout_width="match_parent
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Material 3 是 Google 最新推出的 Material Design UI 组件库。以下是一个简单的 Android 登录布局的 Material 3 实现示例: 首先,在项目的 build.gradle 文件中添加以下依赖项: ```groovy dependencies { implementation 'com.google.android.material:material:1.5.0-alpha02' } ``` 然后,在布局文件中添加以下代码: ```xml <com.google.android.material.textfield.TextInputLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="Email" app:helperText="Enter your email address" app:startIconDrawable="@drawable/ic_email"> <com.google.android.material.textfield.TextInputEditText android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="textEmailAddress" /> </com.google.android.material.textfield.TextInputLayout> <com.google.android.material.textfield.TextInputLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="Password" app:helperText="Enter your password" app:startIconDrawable="@drawable/ic_password" app:endIconDrawable="@drawable/ic_visibility_off" app:endIconMode="password_toggle"> <com.google.android.material.textfield.TextInputEditText android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="textPassword" /> </com.google.android.material.textfield.TextInputLayout> <com.google.android.material.button.MaterialButton android:layout_width="match_parent" android:layout_height="wrap_content" android:text="LOGIN" /> ``` 这里使用了 TextInputLayout 和 TextInputEditText 来创建输入框,以及 MaterialButton 来创建登录按钮。 最后,可以自定义 startIconDrawable、endIconDrawable、helperText 等属性来美化布局。 这是一个基本的 Material 3 登录布局实现,你可以根据自己的需求进行修改和扩展。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值