1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
// app/(tabs)/_layout.tsx
import { Tabs } from 'expo-router';
import { MaterialIcons } from '@expo/vector-icons'; // 官方推荐图标库
export default function TabsLayout() {
return (
<Tabs
screenOptions={{
// --- 全局 Tab 样式 ---
tabBarActiveTintColor: '#1e90ff', // 选中时颜色
tabBarInactiveTintColor: '#888', // 未选中颜色
tabBarStyle: {
height: 60,
paddingBottom: 6,
paddingTop: 6,
borderTopWidth: 1,
borderTopColor: '#eee',
},
// --- 每个页面的 Header 控制(统一设置)---
headerShown: true, // 默认显示 header
headerStyle: {
backgroundColor: '#fff',
},
headerShadowVisible: false, // 去掉 header 底部阴影(iOS/Android 统一)
headerTitleAlign: 'center', // 标题居中
}}
>
<Tabs.Screen
name="index"
options={{
title: '首页',
headerShown: false, // 首页通常不需要 header
tabBarIcon: ({ color, size }) => (
<MaterialIcons name="home" size={size} color={color} />
),
}}
/>
<Tabs.Screen
name="profile"
options={{
title: '我的',
headerTitle: '个人中心', // 自定义 header 标题(不同于 tab 标题)
tabBarIcon: ({ color, size }) => (
<MaterialIcons name="person" size={size} color={color} />
),
}}
/>
<Tabs.Screen
name="settings"
options={{
title: '设置',
tabBarIcon: ({ color, size }) => (
<MaterialIcons name="settings" size={size} color={color} />
),
}}
/>
</Tabs>
);
}
|