forked from microsoft/fluentui-android
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBottomNavigationActivity.kt
105 lines (93 loc) · 4.39 KB
/
BottomNavigationActivity.kt
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
package com.microsoft.fluentuidemo.demos
import android.os.Bundle
import android.view.LayoutInflater
import com.google.android.material.bottomnavigation.LabelVisibilityMode
import com.google.android.material.navigation.NavigationBarView
import com.microsoft.fluentuidemo.DemoActivity
import com.microsoft.fluentuidemo.R
import com.microsoft.fluentuidemo.databinding.ActivityBottomNavigationBinding
// TODO Replace outlined icons with fill icons when selected.
class BottomNavigationActivity : DemoActivity() {
override val contentNeedsScrollableContainer: Boolean
get() = false
private lateinit var bottomNavigationBinding: ActivityBottomNavigationBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
bottomNavigationBinding = ActivityBottomNavigationBinding.inflate(
LayoutInflater.from(container.context),
container,
true
)
bottomNavigationBinding.toggleLabelButton.setOnClickListener {
var labelsState: String = ""
// You can also achieve unlabeled items via @style/Widget.FluentUI.BottomNavigation.Unlabeled
if (bottomNavigationBinding.bottomNavigation.labelVisibilityMode == LabelVisibilityMode.LABEL_VISIBILITY_UNLABELED) {
bottomNavigationBinding.bottomNavigation.labelVisibilityMode =
NavigationBarView.LABEL_VISIBILITY_LABELED
labelsState = "On"
} else {
bottomNavigationBinding.bottomNavigation.labelVisibilityMode =
NavigationBarView.LABEL_VISIBILITY_UNLABELED
labelsState = "Off"
}
it.announceForAccessibility(
resources.getString(
R.string.bottom_navigation_accessibility_labels_state,
labelsState
)
)
}
bottomNavigationBinding.threeMenuItemsButton.setOnClickListener {
bottomNavigationBinding.bottomNavigation.menu.removeItem(R.id.action_calendar)
bottomNavigationBinding.bottomNavigation.menu.removeItem(R.id.action_team)
it.announceForAccessibility(
resources.getString(
R.string.app_accessibility_selected,
resources.getString(R.string.bottom_navigation_three_menu_items_button)
)
)
}
bottomNavigationBinding.fourMenuItemsButton.setOnClickListener {
bottomNavigationBinding.bottomNavigation.menu.removeItem(R.id.action_calendar)
bottomNavigationBinding.bottomNavigation.menu.removeItem(R.id.action_team)
bottomNavigationBinding.bottomNavigation.menu.add(
R.id.bottom_navigation,
R.id.action_calendar,
3,
resources.getString(R.string.bottom_navigation_menu_item_calendar)
).setIcon(R.drawable.ic_calendar_28_regular)
it.announceForAccessibility(
resources.getString(
R.string.app_accessibility_selected,
resources.getString(R.string.bottom_navigation_four_menu_items_button)
)
)
}
bottomNavigationBinding.fiveMenuItemsButton.setOnClickListener {
bottomNavigationBinding.bottomNavigation.menu.removeItem(R.id.action_calendar)
bottomNavigationBinding.bottomNavigation.menu.removeItem(R.id.action_team)
bottomNavigationBinding.bottomNavigation.menu.add(
R.id.bottom_navigation,
R.id.action_calendar,
3,
resources.getString(R.string.bottom_navigation_menu_item_calendar)
).setIcon(R.drawable.ic_calendar_28_regular)
bottomNavigationBinding.bottomNavigation.menu.add(
R.id.bottom_navigation,
R.id.action_team,
4,
resources.getString(R.string.bottom_navigation_menu_item_team)
).setIcon(R.drawable.ic_people_team_28_regular)
it.announceForAccessibility(
resources.getString(
R.string.app_accessibility_selected,
resources.getString(R.string.bottom_navigation_five_menu_items_button)
)
)
}
}
}