溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Java怎么實現側邊欄功能

發(fā)布時間:2021-11-01 14:45:52 來源:億速云 閱讀:579 作者:iii 欄目:編程語言

這篇文章主要講解了“Java怎么實現側邊欄功能”,文中的講解內容簡單清晰,易于學習與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學習“Java怎么實現側邊欄功能”吧!

import 'package:flutter/material.dart';
import 'tabs/Home.dart';
import 'tabs/Category.dart';
import 'tabs/Setting.dart';
class Tabs extends StatefulWidget {
  final index;
  Tabs({Key key, this.index = 0}) : super(key: key);
  @override
  _TabsState createState() => _TabsState(this.index);
}
class _TabsState extends State<Tabs> {
  int _currentIndex = 0;
  _TabsState(index) {
    this._currentIndex = index;
  }
  // 把頁面存放到數組里
  List _pageList = [
    HomePage(),
    CategoryPage(),
    SettingPage(),
  ];
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('首頁'),
      ),
      body: this._pageList[this._currentIndex],
      bottomNavigationBar: BottomNavigationBar(
        // 默認選中第幾項
        currentIndex: this._currentIndex,
        // 導航欄點擊獲取索引值
        onTap: (int index) {
          setState(() {
            this._currentIndex = index;
          });
        },
        // iconSize: 30.0, //icon的大小
        fixedColor: Colors.red, //選中的顏色
        type: BottomNavigationBarType.fixed, //配置底部tabs可以有多個按鈕
        //定義導航欄的圖片+名稱
        items: [
          BottomNavigationBarItem(icon: Icon(Icons.home), title: Text("首頁")),
          BottomNavigationBarItem(
              icon: Icon(Icons.category), title: Text("分類")),
          BottomNavigationBarItem(
              icon: Icon(Icons.settings), title: Text("設置")),
        ],
      ),
      // 這里是核心代碼
      drawer: Drawer(
        child: Column(
          children: <Widget>[
            Row(
              children: <Widget>[
                Expanded(
                    child: UserAccountsDrawerHeader(
                  accountName: Text("任我行RQ"),
                  accountEmail: Text("www.1342134929@qq.com"),
                  currentAccountPicture: CircleAvatar(
                    backgroundImage: NetworkImage(
                        "https://cache.yisu.com/upload/information/20200729/145/36557.jpg"),
                  ),
                  decoration: BoxDecoration(
                      image: DecorationImage(
                    image: NetworkImage(
                        "https://cache.yisu.com/upload/information/20200729/145/36557.jpg"),
                    fit: BoxFit.cover,
                  )),
                ))
              ],
            ),
            ListTile(
              leading: CircleAvatar(
                child: Icon(Icons.home),
              ),
              title: Text("我的空間"),
              onTap: () {
                Navigator.of(context).pop(); //隱藏側邊欄
                Navigator.pushNamed(context, '/NavBar'); //路由的跳轉
              },
            ),
            Divider(),
            ListTile(
              leading: CircleAvatar(
                child: Icon(Icons.people),
              ),
              title: Text("用戶中心"),
            ),
            Divider(),
            ListTile(
              leading: CircleAvatar(
                child: Icon(Icons.settings),
              ),
              title: Text("設置中心"),
            ),
          ],
        ),
      ),
    );
  }
}

感謝各位的閱讀,以上就是“Java怎么實現側邊欄功能”的內容了,經過本文的學習后,相信大家對Java怎么實現側邊欄功能這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是億速云,小編將為大家推送更多相關知識點的文章,歡迎關注!

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI