Перейти к содержанию

NavigationView

Боковая навигация со сворачиваемыми группами пунктов и акцентным выделением выбранного пункта на всю ширину.

Обзор

NavigationView — TreeView, заточенный под левое меню галереи. Группы добавляются через addCategory, страницы через NavigationCategory.addItem, реакция на выбор через onItemSelected. Заголовок группы только сворачивает и разворачивает её и не сбрасывает выбранный пункт. Идентификаторы пунктов уникальны в пределах навигации, выбрать пункт из кода можно через selectItem.

Боковое меню галереи

NavigationView nav = new NavigationView();
nav.addCategory("Basic Input").addItem("slider", "Slider");
nav.onItemSelected(item -> open(item.id()));

Связанные ссылки

  • TreeView: Иерархический древовидный контейнер со сворачиваемыми узлами, кастомными иконками, инлайн-редактированием и выбором.

API

API

Метод Описание
NavigationView() Creates an empty sidebar navigation view.

Create a navigation view

Creates an empty sidebar navigation view.

Categories

Метод Описание
addCategory(String) Appends a category in the expanded state.
addCategory(String, boolean) Appends a category and controls whether its items are initially visible.
categories() Returns categories in insertion order.
clear() Removes every category and item.

NavigationView::addCategory(String)

Add a category

Appends a category in the expanded state.

Параметр Тип Описание
title String Visible category header text.

Возвращает NavigationCategory: The newly created category, used to add navigation items..

NavigationView::addCategory(String, boolean)

Add a category with initial state

Appends a category and controls whether its items are initially visible.

Параметр Тип Описание
title String Visible category header text.
expanded boolean True to show the category items initially; false to collapse the category.

Возвращает NavigationCategory: The newly created category..

NavigationView::categories()

Get categories

Returns categories in insertion order.

Возвращает List: An unmodifiable list of categories in insertion order..

NavigationView::clear()

Clear navigation

Removes every category and item.

Возвращает NavigationView: This view, for fluent configuration..

Items and selection

Метод Описание
items() Returns all items in category and insertion order.
item(String) Looks up an item by its id.
selectedItem() Returns the currently selected item, if any.
selectItem(String) Selects an enabled item by id and expands its category if needed.
onItemSelected(Consumer) Registers a callback invoked when an item is selected.

NavigationView::items()

Get items

Returns all items in category and insertion order.

Возвращает List: An immutable snapshot of all items in insertion order..

NavigationView::item(String)

Find an item

Looks up an item by its id.

Параметр Тип Описание
id String Item id; null returns null.

Возвращает NavigationItem: The matching item, or null when the id is null or unknown..

NavigationView::selectedItem()

Get selected item

Returns the currently selected item, if any.

Возвращает NavigationItem: The selected item, or null when there is no selection..

NavigationView::selectItem(String)

Select an item

Selects an enabled item by id and expands its category if needed.

Параметр Тип Описание
id String Id of an item in this view; unknown or null ids are ignored.

Возвращает NavigationView: This view, for fluent configuration..

NavigationView::onItemSelected(Consumer)

Listen for item selection

Registers a callback invoked when an item is selected.

Параметр Тип Описание
listener Consumer Callback receiving the selected item; null is accepted and ignored.

Возвращает EventSubscription: A subscription that can be cancelled with unsubscribe()..

Appearance

Метод Описание
categoryColor() Returns the mutable background color used for category headers.
categoryColor(ColorView) Sets the category header background color and invalidates the view visually.
categoryTextColor() Returns the mutable text color used for category headers.
categoryTextColor(ColorView) Sets the category header text color and refreshes category rows.

NavigationView::categoryColor()

Get category background color

Returns the mutable background color used for category headers.

Возвращает MutableColor: The mutable RGBA category header background color; components are in [0, 1]..

NavigationView::categoryColor(ColorView)

Set category background color

Sets the category header background color and invalidates the view visually.

Параметр Тип Описание
color ColorView Source RGBA color; null is ignored.

Возвращает NavigationView: This view, for fluent configuration..

NavigationView::categoryTextColor()

Get category text color

Returns the mutable text color used for category headers.

Возвращает MutableColor: The mutable RGBA category header text color; components are in [0, 1]..

NavigationView::categoryTextColor(ColorView)

Set category text color

Sets the category header text color and refreshes category rows.

Параметр Тип Описание
color ColorView Source RGBA color; null is ignored.

Возвращает NavigationView: This view, for fluent configuration..