Tab View (lv_tabview)

Organize content into tabs. Tab buttons can sit on any side of the view.

Edit on GitHub

Overview

Tab View organizes content into tabs. It is built from other widgets:

The tab buttons can be positioned on the top, bottom, left, and right side of the Tab View.

A new tab can be selected either by clicking on a tab button or by sliding horizontally on the content.

Styling

There are no special parts on the Tab View but the base widget and Button (lv_button) Widgets are used to create the Tab View.

Creating a Tab View

lv_tabview_create(parent) creates a new empty Tab View.

Adding tabs

New tabs can be added with lv_tabview_add_tab(tabview, "Tab name"). This will return a pointer to a base widget where the tab's content can be created.

Renaming tabs

A tab can be renamed with lv_tabview_set_tab_text(tabview, tab_id, "New Name").

To select a new tab you can:

The horizontal swipe gesture lives on the content container, so it can be disabled by removing the LV_OBJ_FLAG_SCROLLABLE flag from lv_tabview_get_content(tabview). After that, tabs can only be switched by tapping a tab button or by calling lv_tabview_set_active.

Setting tab bar position

Using the lv_tabview_set_tab_bar_position(tabview, LV_DIR_LEFT/RIGHT/TOP/BOTTOM) the tab bar can be moved to any side.

Setting tab bar size

The size of the tab bar can be adjusted by lv_tabview_set_tab_bar_size(tabview, size). When tabs are on the top or bottom, this means the height of the tab bar, and when they are on the sides, it means the width.

Tab bar style

The tab view exposes three independent style targets: the tab view body, the tab bar container, and individual tab buttons. Each can be styled separately to customize background, padding, indicator colors, and per-tab accents.

Accessing the parts

Tab button content

Tab buttons are regular widgets, so additional children — such as a switch, icon, or status indicator — can be parented to a tab button to enrich its caption without replacing the default tab bar.

Events

LV_EVENT_VALUE_CHANGED is sent when a new tab is selected by sliding or clicking the tab button. lv_tabview_get_tab_active(tabview) returns the zero based index of the current tab.

Learn more about Events emitted by all Widgets.

Keys

Keys have effect only on the tab buttons. Programmatically add these buttons to a group if required.

Learn more about Keys.

Last updated on

On this page