【发布时间】:2019-12-29 03:22:40
【问题描述】:
这是我对这个主题的第二个线程,这次我将添加一张图片和完整的代码。 导航栏正在工作,但我想要一个被按下的指示器(图标下的文本已经放大了一点,但这还不够) 我希望按下的部分的背景比其他部分更亮。 这怎么可能?我对 Flutter 真的很陌生,目前这是唯一让我完全困惑的编程语言。 screenshot 在代码中,我只包含了一个图标字体(字体真棒)和导航栏指向的 3 个页面。 (neu,beliebt,profil)
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'Neu.dart';
import 'Beliebt.dart';
import 'Profil.dart';
void main() => runApp(new MyApp());
class MyApp extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return MyAppState();
}
}
class MyAppState extends State<MyApp> {
int _selectedTab = 0;
final _pageOptions = [
NeuPage(),
BeliebtPage(),
ProfilPage(),
];
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
primaryColor: Colors.deepOrangeAccent,
primaryTextTheme: TextTheme(
title: TextStyle(color: Colors.white),
)),
home: Scaffold(
appBar: AppBar(
title: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.asset(
'assets/logo_straight.png',
fit: BoxFit.contain,
height: 32,
),
],
),
),
body: _pageOptions[_selectedTab],
bottomNavigationBar: BottomNavigationBar(
currentIndex: _selectedTab,
backgroundColor: Colors.deepOrangeAccent,
onTap: (int index) {
setState(() {
_selectedTab = index;
});
},
items: [
BottomNavigationBarItem(
icon: Icon(FontAwesomeIcons.quoteRight, color: Colors.white),
title: Text('Neu', style: TextStyle(color: Colors.white),
)
),
BottomNavigationBarItem(
icon: Icon(Icons.whatshot, color: Colors.white),
title: Text('Beliebt', style: TextStyle(color: Colors.white),
)
),
BottomNavigationBarItem(
icon: Icon(Icons.account_circle, color: Colors.white),
title: Text('Profil', style: TextStyle(color: Colors.white),
)
),
],
),
),
);
}
}
【问题讨论】:
-
欢迎 Mika 使用 stackoverflow ,尝试使用 activeIcon : Icon(Icons.whatshot, color: Colors.green),
-
嗯,只会改变图标的颜色。但我想更改所选项目的背景