android仿咸鱼底部导航,Flutter FloatingActionButton 实现类似咸鱼App底部导航凸起按钮...

编程入门 行业动态 更新时间:2024-10-08 20:36:41

android仿<a href=https://www.elefans.com/category/jswz/34/1762853.html style=咸鱼底部导航,Flutter FloatingActionButton 实现类似咸鱼App底部导航凸起按钮..."/>

android仿咸鱼底部导航,Flutter FloatingActionButton 实现类似咸鱼App底部导航凸起按钮...

FloatingActionButton简称FAB,可以实现浮动按钮,也可以实现类似咸鱼app 的凸起导航按钮

一. FloatingActionButton常用属性

child:子视图,一般为Icon,不推荐使用文字

tooltip:FAB被长按时显示,也是无障碍功能

backgroundColor:背景颜色

elevation:未点击时候的阴影

hignlightElevation:点击是阴影值,默认是12.0

onPressed:点击事件回调

shape:可以定位FAB的形状等

mini:是否是mini类型默认是false

二.咸鱼凸起按钮实现

1.咸鱼效果

image.png

2.实现思路:用浮动按钮盖住tab按钮

image.png

3.代码实现

Scaffold组件 添加floatingActionButton按钮,修改floatingActionButton的大小和颜色 为合适状态

通过设置margin 来调整 floatingActionButton 的位置

Scaffold组件 添加floatingActionButton按钮,修改floatingActionButton的大小和颜色 为合适状态

Scaffold组件 添加BottomNavigationBar 底部按钮

class TrackerMainScreen extends StatefulWidget {

const TrackerMainScreen(this._deviceId);

BottomButton createState() => BottomButton();

}

class BottomButton extends State {

var currentIndex = 0;

@override

Widget build(BuildContext context) {

return Scaffold(

floatingActionButton: Container(

height: 80,

width: 80,

margin: EdgeInsets.only(bottom: 15),

padding: EdgeInsets.all(10),

decoration: BoxDecoration(

borderRadius: BorderRadius.circular(40), color: Colors.white),

child: FloatingActionButton(

child: Icon(Icons.info),

onPressed: () {

print("点击浮动按钮");

},

),

),

floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,

bottomNavigationBar: BottomNavigationBar(

currentIndex: currentIndex,

onTap: (int index) {

setState(() {

this.currentIndex = index;

});

},

fixedColor: Colors.pink,

type: BottomNavigationBarType.fixed,

items: [

BottomNavigationBarItem(

title: Text("首页", style: TextStyle(color: Colors.grey)),

icon: Icon(Icons.list, color: Colors.grey)),

BottomNavigationBarItem(

title: Text("发布", style: TextStyle(color: Colors.grey)),

icon: Icon(Icons.satellite, color: Colors.grey)),

BottomNavigationBarItem(

title: Text("故事", style: TextStyle(color: Colors.grey)),

icon: Icon(Icons.account_balance, color: Colors.grey)),

],

),

body: Container(color: Colors.amber,),

);

}

}

4.效果图

image.png

三. 注意

BottomNavigationBar 和FloatingActionButton 都在Scaffold 组件中创建

BottomNavigationBarItem中的icon 是必须写的

凸起按钮实现思路:用FloatingActionButton盖住BottomNavigationBar

更多推荐

android仿咸鱼底部导航,Flutter FloatingActionButton 实现类似咸鱼App底部导航凸起按钮...

本文发布于:2024-02-14 07:51:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1762712.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:咸鱼   按钮   类似   android   Flutter

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!