Contents Menu Expand Light mode Dark mode System, in dark mode System, in light mode View documentation source on GitHub Skip to content
LVGL 9.3 documentation
Light Logo Dark Logo
  • Introduction
  • Getting Started
  • Examples
  • Integration and Drivers
    • Adding LVGL to Your Project
      • Getting LVGL
      • Building LVGL
      • Configuration
      • Connecting LVGL to Your Hardware
      • Timer Handler
      • Threading Considerations
      • Other Platforms and Tools
    • Bindings
      • Output API as JSON Data
      • Cpp
      • JavaScript
      • MicroPython
      • PikaScript
    • Build Systems
      • make
      • CMake
    • Chip vendors
      • Alif
      • Arm
      • Espressif (ESP32 Chip Series)
      • NXP
      • Renesas
        • Built-in Drivers
        • RA Family
        • RX Family
        • RZ/G Family
        • RZ/A Family
        • Supported Boards
      • STM32
    • Drivers
      • Display
        • Linux Framebuffer Driver
        • FT81x
        • Generic MIPI DCS compatible LCD Controller driver
        • ILI9341 LCD Controller driver
        • Step-by-step Guide: How to use the LVGL v9 LCD drivers with STM32 devices
        • NXP eLCDIF
        • Renesas GLCDC
        • STM32 LTDC Driver
        • ST7735 LCD Controller driver
        • ST7789 LCD Controller driver
        • ST7796 LCD Controller driver
      • Libinput Driver
      • OpenGL ES Display/Inputs Driver
      • Touchpad
        • Linux Evdev Driver
        • FT6X36
      • Wayland Display/Inputs driver
      • Windows Display/Inputs driver
      • X11 Display/Inputs driver
      • UEFI Display/Inputs driver
      • SDL Driver
    • Renderers and GPUs
      • Software Renderer
      • Arm-2D GPU
      • Espressif Pixel Processing Accelerator
      • NemaGFX Acceleration
      • NXP PXP GPU
      • NXP VGLite GPU
      • NXP G2D GPU
      • SDL Renderer
      • STM32 DMA2D GPU
      • VG-Lite General GPU
    • Frameworks
      • Arduino
      • PlatformIO
      • Tasmota and berry
    • IDEs
      • MDK
      • Simulator on PC
    • (RT)OS
      • FreeRTOS
      • MQX RTOS
      • NuttX RTOS
      • PX5 RTOS
      • QNX
      • RT-Thread RTOS
      • Yocto
        • Yocto Project Core Components
        • LVGL in Yocto
        • Yocto Project Terms
      • Buildroot
        • Quick Setup
        • RPi4 custom image
        • LVGL application
      • Zephyr
      • Torizon OS
    • Boards
      • Toradex
      • Riverdi
      • Viewe
  • Common Widget Features
    • Widget Basics
    • Positions, Sizes and Layouts
    • Layers
    • Styles
      • Styles Overview
      • Style Properties
    • Events
    • Layouts
      • Flex
      • Grid
    • Scrolling
  • All Widgets
    • Base Widget (lv_obj)
    • 3D Texture (lv_3dtexture)
    • Animation Image (lv_animimg)
    • Arc (lv_arc)
    • Arc Label (lv_arclabel)
    • Bar (lv_bar)
    • Button (lv_button)
    • Button Matrix (lv_buttonmatrix)
    • Calendar (lv_calendar)
    • Canvas (lv_canvas)
    • Chart (lv_chart)
    • Checkbox (lv_checkbox)
    • Drop-Down List (lv_dropdown)
    • Image (lv_image)
    • Image Button (lv_imagebutton)
    • Keyboard (lv_keyboard)
    • Label (lv_label)
    • LED (lv_led)
    • Line (lv_line)
    • List (lv_list)
    • Lottie (lv_lottie)
    • Menu (lv_menu)
    • Message Box (lv_msgbox)
    • Roller (lv_roller)
    • Scale (lv_scale)
    • Slider (lv_slider)
    • Spangroup (lv_spangroup)
    • Spinbox (lv_spinbox)
    • Spinner (lv_spinner)
    • Switch (lv_switch)
    • Table (lv_table)
    • Tab View (lv_tabview)
    • Text Area (lv_textarea)
    • Tile View (lv_tileview)
    • Window (lv_win)
    • New Widget
  • Main Modules
    • Display (lv_display)
      • Overview
      • Setting Up Your Display(s)
      • Screen Layers
      • Color Format
      • Refreshing
      • Events
      • API
      • Changing Resolution
      • Inactivity Measurement
      • Rotation
      • Constraints on Redrawn Area
      • Tiled Rendering
      • Extending/Combining Displays
    • Input Device (lv_indev)
    • Color (lv_color)
    • Font (lv_font)
    • Images (lv_image)
    • Timer (lv_timer)
    • Animation (lv_anim)
    • File System (lv_fs_drv)
    • Drawing
      • Draw Pipeline
      • Draw API
      • Draw Layers
      • Draw Descriptors
  • Auxiliary Modules
    • File Explorer
    • Font Manager
    • Fragment
    • Grid navigation
    • Pinyin IME
    • Image font
    • Monkey
    • Widget ID
    • Widget Properties
    • Observer
      • How to Use
      • Examples
    • Snapshot
    • UI Testing
    • XML - Declarative UI
      • Introduction
      • Component Library
      • Project
      • Syntax
      • Components
      • Screens
      • Widgets
      • Preview
      • API
      • Styles
      • Constants
      • View
      • Fonts
      • Images
      • Events
      • Subjects
      • Animations
      • Translations
  • 3rd-Party Libraries
    • Arduino ESP littlefs
    • Arduino SD
    • Barcode
    • BMP Decoder
    • FFmpeg Support
    • FreeType Support
    • File System Interfaces
    • GIF Decoder
    • littlefs
    • libjpeg-turbo Decoder
    • libpng Decoder
    • LodePNG Decoder
    • QR Code
    • RLE Decompression
    • Rlottie Player
    • SVG Support
    • Tiny TTF font engine
    • Tiny JPEG Decompressor (TJpgDec)
  • Debugging
    • GDB Plug-In
    • Logging
    • Profiler
    • VG-Lite Simulator
  • Contributing
    • Introduction
    • Ways to Contribute
    • Pull Requests
    • Developer Certification of Origin (DCO)
    • Coding Style
  • Change Log
  • API
    • lv_conf_kconfig.h
    • lv_conf_internal.h
    • lv_api_map_v9_1.h
    • lvgl_private.h
    • lvgl.h
    • lv_api_map_v9_0.h
    • lv_api_map_v8.h
    • lv_init.h
    • stdlib
      • lv_string.h
      • lv_mem.h
      • lv_sprintf.h
      • lv_mem_private.h
      • builtin
        • lv_tlsf_private.h
        • lv_tlsf.h
    • core
      • lv_global.h
      • lv_obj_style_private.h
      • lv_obj_scroll_private.h
      • lv_obj_class.h
      • lv_obj_tree.h
      • lv_refr.h
      • lv_group_private.h
      • lv_obj_scroll.h
      • lv_obj_property.h
      • lv_obj_private.h
      • lv_obj_style.h
      • lv_obj_style_gen.h
      • lv_obj.h
      • lv_obj_draw_private.h
      • lv_obj_pos.h
      • lv_refr_private.h
      • lv_obj_event.h
      • lv_obj_event_private.h
      • lv_obj_draw.h
      • lv_obj_class_private.h
      • lv_group.h
    • osal
      • lv_mqx.h
      • lv_rtthread.h
      • lv_windows.h
      • lv_cmsis_rtos2.h
      • lv_os_private.h
      • lv_linux_private.h
      • lv_pthread.h
      • lv_os.h
      • lv_os_none.h
      • lv_freertos.h
      • lv_sdl2.h
    • themes
      • lv_theme_private.h
      • lv_theme.h
      • simple
        • lv_theme_simple.h
      • mono
        • lv_theme_mono.h
      • default
        • lv_theme_default.h
    • others
      • file_explorer
        • lv_file_explorer.h
        • lv_file_explorer_private.h
      • xml
        • lv_xml_private.h
        • lv_xml_component.h
        • lv_xml_parser.h
        • lv_xml.h
        • lv_xml_style.h
        • lv_xml_widget.h
        • lv_xml_utils.h
        • lv_xml_component_private.h
        • lv_xml_base_types.h
        • lv_xml_update.h
        • parsers
          • lv_xml_bar_parser.h
          • lv_xml_slider_parser.h
          • lv_xml_spangroup_parser.h
          • lv_xml_tabview_parser.h
          • lv_xml_dropdown_parser.h
          • lv_xml_button_parser.h
          • lv_xml_roller_parser.h
          • lv_xml_event_parser.h
          • lv_xml_keyboard_parser.h
          • lv_xml_obj_parser.h
          • lv_xml_calendar_parser.h
          • lv_xml_textarea_parser.h
          • lv_xml_checkbox_parser.h
          • lv_xml_label_parser.h
          • lv_xml_buttonmatrix_parser.h
          • lv_xml_arc_parser.h
          • lv_xml_chart_parser.h
          • lv_xml_scale_parser.h
          • lv_xml_canvas_parser.h
          • lv_xml_image_parser.h
          • lv_xml_table_parser.h
      • ime
        • lv_ime_pinyin.h
        • lv_ime_pinyin_private.h
      • fragment
        • lv_fragment.h
        • lv_fragment_private.h
      • gridnav
        • lv_gridnav.h
      • observer
        • lv_observer_private.h
        • lv_observer.h
      • monkey
        • lv_monkey_private.h
        • lv_monkey.h
      • test
        • lv_test_helpers.h
        • lv_test_indev.h
        • lv_test.h
        • lv_test_private.h
        • lv_test_indev_gesture.h
        • lv_test_display.h
        • lv_test_screenshot_compare.h
      • font_manager
        • lv_font_manager.h
        • lv_font_manager_recycle.h
      • snapshot
        • lv_snapshot.h
      • sysmon
        • lv_sysmon.h
        • lv_sysmon_private.h
      • imgfont
        • lv_imgfont.h
    • display
      • lv_display.h
      • lv_display_private.h
    • libs
      • lodepng
        • lv_lodepng.h
      • bmp
        • lv_bmp.h
      • barcode
        • lv_barcode.h
        • lv_barcode_private.h
      • rle
        • lv_rle.h
      • bin_decoder
        • lv_bin_decoder.h
      • qrcode
        • lv_qrcode.h
        • lv_qrcode_private.h
      • tiny_ttf
        • lv_tiny_ttf.h
      • svg
        • lv_svg_decoder.h
        • lv_svg_render.h
        • lv_svg_token.h
        • lv_svg_parser.h
        • lv_svg.h
      • tjpgd
        • lv_tjpgd.h
      • freetype
        • lv_freetype.h
        • lv_freetype_private.h
      • ffmpeg
        • lv_ffmpeg_private.h
        • lv_ffmpeg.h
      • libpng
        • lv_libpng.h
      • libjpeg_turbo
        • lv_libjpeg_turbo.h
      • rlottie
        • lv_rlottie.h
        • lv_rlottie_private.h
      • fsdrv
        • lv_fsdrv.h
      • gif
        • lv_gif.h
        • lv_gif_private.h
    • font
      • lv_font_fmt_txt_private.h
      • lv_binfont_loader.h
      • lv_symbol_def.h
      • lv_font.h
      • lv_font_fmt_txt.h
    • widgets
      • button
        • lv_button_private.h
        • lv_button.h
      • msgbox
        • lv_msgbox.h
        • lv_msgbox_private.h
      • arclabel
        • lv_arclabel_private.h
        • lv_arclabel.h
      • slider
        • lv_slider.h
        • lv_slider_private.h
      • list
        • lv_list.h
      • tileview
        • lv_tileview.h
        • lv_tileview_private.h
      • objx_templ
        • lv_objx_templ.h
      • label
        • lv_label.h
        • lv_label_private.h
      • menu
        • lv_menu.h
        • lv_menu_private.h
      • buttonmatrix
        • lv_buttonmatrix.h
        • lv_buttonmatrix_private.h
      • scale
        • lv_scale_private.h
        • lv_scale.h
      • textarea
        • lv_textarea_private.h
        • lv_textarea.h
      • line
        • lv_line.h
        • lv_line_private.h
      • 3dtexture
        • lv_3dtexture.h
        • lv_3dtexture_private.h
      • arc
        • lv_arc.h
        • lv_arc_private.h
      • span
        • lv_span.h
        • lv_span_private.h
      • win
        • lv_win.h
        • lv_win_private.h
      • calendar
        • lv_calendar_header_arrow.h
        • lv_calendar_private.h
        • lv_calendar.h
        • lv_calendar_header_dropdown.h
        • lv_calendar_chinese.h
      • canvas
        • lv_canvas_private.h
        • lv_canvas.h
      • animimage
        • lv_animimage_private.h
        • lv_animimage.h
      • property
        • lv_obj_property_names.h
        • lv_style_properties.h
      • switch
        • lv_switch_private.h
        • lv_switch.h
      • image
        • lv_image.h
        • lv_image_private.h
      • roller
        • lv_roller_private.h
        • lv_roller.h
      • table
        • lv_table_private.h
        • lv_table.h
      • dropdown
        • lv_dropdown_private.h
        • lv_dropdown.h
      • lottie
        • lv_lottie.h
        • lv_lottie_private.h
      • spinbox
        • lv_spinbox.h
        • lv_spinbox_private.h
      • led
        • lv_led_private.h
        • lv_led.h
      • tabview
        • lv_tabview.h
        • lv_tabview_private.h
      • bar
        • lv_bar.h
        • lv_bar_private.h
      • checkbox
        • lv_checkbox_private.h
        • lv_checkbox.h
      • spinner
        • lv_spinner.h
      • imagebutton
        • lv_imagebutton.h
        • lv_imagebutton_private.h
      • keyboard
        • lv_keyboard.h
        • lv_keyboard_private.h
      • chart
        • lv_chart_private.h
        • lv_chart.h
    • draw
      • lv_image_dsc.h
      • lv_draw.h
      • lv_draw_buf_private.h
      • lv_draw_3d.h
      • lv_draw_vector.h
      • lv_draw_arc.h
      • lv_draw_label_private.h
      • lv_draw_vector_private.h
      • lv_draw_private.h
      • lv_draw_image.h
      • lv_draw_rect_private.h
      • lv_draw_triangle_private.h
      • lv_image_decoder.h
      • lv_draw_mask.h
      • lv_draw_mask_private.h
      • lv_image_decoder_private.h
      • lv_draw_line.h
      • lv_draw_buf.h
      • lv_draw_rect.h
      • lv_draw_triangle.h
      • lv_draw_image_private.h
      • lv_draw_label.h
      • espressif
        • ppa
          • lv_draw_ppa_private.h
          • lv_draw_ppa.h
      • vg_lite
        • lv_vg_lite_grad.h
        • lv_vg_lite_stroke.h
        • lv_vg_lite_math.h
        • lv_draw_vg_lite.h
        • lv_draw_vg_lite_type.h
        • lv_vg_lite_path.h
        • lv_vg_lite_pending.h
        • lv_vg_lite_utils.h
        • lv_vg_lite_decoder.h
      • opengles
        • lv_draw_opengles.h
      • renesas
        • dave2d
          • lv_draw_dave2d.h
          • lv_draw_dave2d_utils.h
      • dma2d
        • lv_draw_dma2d.h
        • lv_draw_dma2d_private.h
      • sdl
        • lv_draw_sdl.h
      • sw
        • lv_draw_sw_utils.h
        • lv_draw_sw.h
        • lv_draw_sw_mask_private.h
        • lv_draw_sw_private.h
        • lv_draw_sw_grad.h
        • lv_draw_sw_mask.h
        • blend
          • lv_draw_sw_blend_to_rgb565.h
          • lv_draw_sw_blend_to_rgb888.h
          • lv_draw_sw_blend_to_l8.h
          • lv_draw_sw_blend_to_argb8888.h
          • lv_draw_sw_blend_to_rgb565_swapped.h
          • lv_draw_sw_blend_to_i1.h
          • lv_draw_sw_blend_to_argb8888_premultiplied.h
          • lv_draw_sw_blend_to_al88.h
          • lv_draw_sw_blend_private.h
          • lv_draw_sw_blend.h
          • neon
            • lv_blend_neon.h
          • helium
            • lv_blend_helium.h
          • arm2d
            • lv_blend_arm2d.h
        • arm2d
          • lv_draw_sw_helium.h
          • lv_draw_sw_arm2d.h
      • nxp
        • pxp
          • lv_pxp_cfg.h
          • lv_draw_pxp.h
          • lv_pxp_osa.h
          • lv_pxp_utils.h
        • g2d
          • lv_g2d_utils.h
          • lv_g2d_buf_map.h
          • lv_draw_g2d.h
        • vglite
          • lv_vglite_utils.h
          • lv_vglite_buf.h
          • lv_vglite_path.h
          • lv_draw_vglite.h
          • lv_vglite_matrix.h
      • nema_gfx
        • lv_draw_nema_gfx_utils.h
        • lv_draw_nema_gfx.h
        • lv_nema_gfx_path.h
    • indev
      • lv_indev_gesture_private.h
      • lv_indev_scroll.h
      • lv_indev_private.h
      • lv_indev_gesture.h
      • lv_indev.h
    • misc
      • lv_fs.h
      • lv_timer.h
      • lv_circle_buf.h
      • lv_math.h
      • lv_timer_private.h
      • lv_color.h
      • lv_bidi.h
      • lv_text_private.h
      • lv_event.h
      • lv_color_op_private.h
      • lv_text.h
      • lv_bidi_private.h
      • lv_matrix.h
      • lv_log.h
      • lv_tree.h
      • lv_profiler_builtin.h
      • lv_text_ap.h
      • lv_area.h
      • lv_lru.h
      • lv_anim_timeline.h
      • lv_anim.h
      • lv_fs_private.h
      • lv_rb.h
      • lv_async.h
      • lv_palette.h
      • lv_grad.h
      • lv_profiler_builtin_private.h
      • lv_area_private.h
      • lv_style_private.h
      • lv_profiler.h
      • lv_utils.h
      • lv_assert.h
      • lv_anim_private.h
      • lv_ll.h
      • lv_rb_private.h
      • lv_event_private.h
      • lv_style_gen.h
      • lv_style.h
      • lv_color_op.h
      • lv_array.h
      • lv_iter.h
      • lv_templ.h
      • cache
        • lv_cache.h
        • lv_cache_entry_private.h
        • lv_cache_private.h
        • lv_cache_entry.h
        • instance
          • lv_image_cache.h
          • lv_image_header_cache.h
          • lv_cache_instance.h
        • class
          • lv_cache_lru_ll.h
          • lv_cache_class.h
          • lv_cache_lru_rb.h
    • drivers
      • lv_drivers.h
      • evdev
        • lv_evdev_private.h
        • lv_evdev.h
      • libinput
        • lv_libinput_private.h
        • lv_xkb.h
        • lv_libinput.h
        • lv_xkb_private.h
      • display
        • ili9341
          • lv_ili9341.h
        • st7789
          • lv_st7789.h
        • tft_espi
          • lv_tft_espi.h
        • nxp_elcdif
          • lv_nxp_elcdif.h
        • lcd
          • lv_lcd_generic_mipi.h
        • st_ltdc
          • lv_st_ltdc.h
        • ft81x
          • lv_ft81x_defines.h
          • lv_ft81x.h
        • fb
          • lv_linux_fbdev.h
        • renesas_glcdc
          • lv_renesas_glcdc.h
        • st7735
          • lv_st7735.h
        • drm
          • lv_linux_drm.h
        • st7796
          • lv_st7796.h
      • wayland
        • lv_wl_touch.h
        • lv_wayland.h
        • lv_wl_keyboard.h
        • lv_wayland_private.h
        • lv_wl_pointer_axis.h
        • lv_wl_pointer.h
        • lv_wl_window.h
        • lv_wayland_smm.h
      • x11
        • lv_x11.h
      • sdl
        • lv_sdl_window.h
        • lv_sdl_mouse.h
        • lv_sdl_keyboard.h
        • lv_sdl_mousewheel.h
        • lv_sdl_private.h
      • windows
        • lv_windows_input_private.h
        • lv_windows_display.h
        • lv_windows_context.h
        • lv_windows_input.h
      • nuttx
        • lv_nuttx_touchscreen.h
        • lv_nuttx_entry.h
        • lv_nuttx_cache.h
        • lv_nuttx_lcd.h
        • lv_nuttx_fbdev.h
        • lv_nuttx_image_cache.h
        • lv_nuttx_libuv.h
        • lv_nuttx_profiler.h
      • glfw
        • lv_glfw_window_private.h
        • lv_glfw_window.h
        • lv_opengles_texture.h
        • lv_opengles_driver.h
        • lv_opengles_debug.h
      • uefi
        • lv_uefi_display.h
        • lv_uefi_edk2.h
        • lv_uefi_private.h
        • lv_uefi_gnu_efi.h
        • lv_uefi_indev.h
        • lv_uefi_std_wrapper.h
        • lv_uefi.h
        • lv_uefi_context.h
      • qnx
        • lv_qnx.h
    • tick
      • lv_tick_private.h
      • lv_tick.h
    • layouts
      • lv_layout_private.h
      • lv_layout.h
      • grid
        • lv_grid.h
      • flex
        • lv_flex.h
Back to top
View this page

Drop-Down List (lv_dropdown)¶

Overview¶

The Drop-Down List allows the user to select a value from a list.

The Drop-Down List is closed by default and displays a single value or predefined text. When activated (by click on the Drop-Down List), a list is created from which the user may select one item. When the user selects a new value, the list is deleted again.

The Drop-down list is added to the default group (if one is set). The Drop-down list is an editable Widget allowing list-item selection via encoder or keyboard navigation as well.

Parts and Styles¶

The Drop-Down List Widget is built from the elements: "button" and "list" (lightweight versions of the Button and List Widgets).

Button¶

  • LV_PART_MAIN Background of button, uses the typical background and text style properties for its text.

  • LV_PART_INDICATOR Typically an arrow symbol that can be an Image or text (e.g. LV_SYMBOL).

The button goes to LV_STATE_CHECKED when it's opened.

List¶

  • LV_PART_MAIN The list itself; uses the typical background style properties. max_height can be used to limit the height of the list.

  • LV_PART_SCROLLBAR The scrollbar background, border, shadow properties and width (for its own width) and right padding for the spacing on the right.

  • LV_PART_SELECTED Refers to the currently pressed, checked or pressed+checked option. Also uses the typical background style properties.

The list is shown/hidden on open/close. To add styles to it use lv_dropdown_get_list(dropdown) to get the list object. Example:

lv_obj_t * list = lv_dropdown_get_list(dropdown) /* Get list */
lv_obj_add_style(list, &my_style, selector)      /* Add styles to list */

Alternatively the theme can be extended with new styles.

Usage¶

List items¶

The list items are passed to the Drop-Down List as a newline-separated list in a string as the options argument to lv_dropdown_set_options(dropdown, options). Each list item should be separated by \n. Example: "First\nSecond\nThird". This string is copied by the Drop-Down List, so its contents do not need to remain available beyond this call.

The lv_dropdown_add_option(dropdown, "New option", pos) function inserts a new option at index pos.

To save memory the options can be set from a static (const) string as well with lv_dropdown_set_options_static(dropdown, options). In this case the options string's contents must remain available for the life of the Drop-Down List and lv_dropdown_add_option() cannot be used.

You can select an option programmatically with lv_dropdown_set_selected(dropdown, id), where id is the index of the target option.

Get selected option¶

To get the index of the selected option, use lv_dropdown_get_selected(dropdown).

lv_dropdown_get_selected_str(dropdown, buf, buf_size) copies the name of the selected option to buf.

Direction¶

The list can be created on any side. The default LV_DIR_BOTTOM can be modified using lv_dropdown_set_dir(dropdown, LV_DIR_LEFT).

If the list would be vertically out of the screen, it will be aligned to the edge.

Symbol¶

A symbol (typically an arrow) can be added to the Drop-Down List with lv_dropdown_set_symbol(dropdown, LV_SYMBOL_...)

If the direction of the Drop-Down List is LV_DIR_LEFT the symbol will be shown on the left, otherwise on the right.

Show selected¶

The main part can either show the selected item or static text. If static is set with lv_dropdown_set_text(dropdown, "Some text") it will be shown regardless of the selected item. If the text is NULL the selected option is displayed on the button.

Programmatically open/close¶

To programmatically open or close the Drop-Down List use lv_dropdown_open(dropdown) or lv_dropdown_close(dropdown).

Events¶

  • LV_EVENT_VALUE_CHANGED Sent when a new option is selected or the list is opened/closed.

  • LV_EVENT_CANCEL Sent when list is closed.

  • LV_EVENT_READY Sent when list is opened.

Further Reading

Learn more about Base-Widget Events emitted by all Widgets.

Learn more about Events.

Keys¶

  • LV_KEY_RIGHT/DOWN Select next list item.

  • LV_KEY_LEFT/UP Select previous list item.

  • LV_KEY_ENTER Apply selected list item (sends LV_EVENT_VALUE_CHANGED event and closes Drop-Down List).

Further Reading

Learn more about Keys.

Example¶

Simple Drop down list¶

C code  

 View on GitHub
#include "../../lv_examples.h"
#if LV_USE_DROPDOWN && LV_BUILD_EXAMPLES

static void event_handler(lv_event_t * e)
{
    lv_event_code_t code = lv_event_get_code(e);
    lv_obj_t * obj = lv_event_get_target_obj(e);
    if(code == LV_EVENT_VALUE_CHANGED) {
        char buf[32];
        lv_dropdown_get_selected_str(obj, buf, sizeof(buf));
        LV_LOG_USER("Option: %s", buf);
    }
}

void lv_example_dropdown_1(void)
{

    /*Create a normal drop down list*/
    lv_obj_t * dd = lv_dropdown_create(lv_screen_active());
    lv_dropdown_set_options(dd, "Apple\n"
                            "Banana\n"
                            "Orange\n"
                            "Cherry\n"
                            "Grape\n"
                            "Raspberry\n"
                            "Melon\n"
                            "Orange\n"
                            "Lemon\n"
                            "Nuts");

    lv_obj_align(dd, LV_ALIGN_TOP_MID, 0, 20);
    lv_obj_add_event_cb(dd, event_handler, LV_EVENT_ALL, NULL);
}


#endif

Drop down in four directions¶

C code  

 View on GitHub
#include "../../lv_examples.h"
#if LV_USE_DROPDOWN && LV_BUILD_EXAMPLES

/**
 * Create a drop down, up, left and right menus
 */
void lv_example_dropdown_2(void)
{
    static const char * opts = "Apple\n"
                               "Banana\n"
                               "Orange\n"
                               "Melon";

    lv_obj_t * dd;
    dd = lv_dropdown_create(lv_screen_active());
    lv_dropdown_set_options_static(dd, opts);
    lv_obj_align(dd, LV_ALIGN_TOP_MID, 0, 10);

    dd = lv_dropdown_create(lv_screen_active());
    lv_dropdown_set_options_static(dd, opts);
    lv_dropdown_set_dir(dd, LV_DIR_BOTTOM);
    lv_dropdown_set_symbol(dd, LV_SYMBOL_UP);
    lv_obj_align(dd, LV_ALIGN_BOTTOM_MID, 0, -10);

    dd = lv_dropdown_create(lv_screen_active());
    lv_dropdown_set_options_static(dd, opts);
    lv_dropdown_set_dir(dd, LV_DIR_RIGHT);
    lv_dropdown_set_symbol(dd, LV_SYMBOL_RIGHT);
    lv_obj_align(dd, LV_ALIGN_LEFT_MID, 10, 0);

    dd = lv_dropdown_create(lv_screen_active());
    lv_dropdown_set_options_static(dd, opts);
    lv_dropdown_set_dir(dd, LV_DIR_LEFT);
    lv_dropdown_set_symbol(dd, LV_SYMBOL_LEFT);
    lv_obj_align(dd, LV_ALIGN_RIGHT_MID, -10, 0);
}

#endif

Menu¶

C code  

 View on GitHub
#include "../../lv_examples.h"
#if LV_USE_DROPDOWN && LV_BUILD_EXAMPLES

static void event_cb(lv_event_t * e)
{
    lv_obj_t * dropdown = lv_event_get_target_obj(e);
    char buf[64];
    lv_dropdown_get_selected_str(dropdown, buf, sizeof(buf));
    LV_LOG_USER("'%s' is selected", buf);
}

/**
 * Create a menu from a drop-down list and show some drop-down list features and styling
 */
void lv_example_dropdown_3(void)
{
    /*Create a drop down list*/
    lv_obj_t * dropdown = lv_dropdown_create(lv_screen_active());
    lv_obj_align(dropdown, LV_ALIGN_TOP_LEFT, 10, 10);
    lv_dropdown_set_options(dropdown, "New project\n"
                            "New file\n"
                            "Save\n"
                            "Save as ...\n"
                            "Open project\n"
                            "Recent projects\n"
                            "Preferences\n"
                            "Exit");

    /*Set a fixed text to display on the button of the drop-down list*/
    lv_dropdown_set_text(dropdown, "Menu");

    /*Use a custom image as down icon and flip it when the list is opened*/
    LV_IMAGE_DECLARE(img_caret_down);
    lv_dropdown_set_symbol(dropdown, &img_caret_down);
    lv_obj_set_style_transform_rotation(dropdown, 1800, LV_PART_INDICATOR | LV_STATE_CHECKED);

    /*In a menu we don't need to show the last clicked item*/
    lv_dropdown_set_selected_highlight(dropdown, false);

    lv_obj_add_event_cb(dropdown, event_cb, LV_EVENT_VALUE_CHANGED, NULL);
}

#endif

API¶

lv_api_map_v8.h

lv_dropdown.h

lv_dropdown_private.h

lv_obj_property_names.h

lv_observer.h

Next
Image (lv_image)
Previous
Checkbox (lv_checkbox)
Copyright © 2021-2025, LVGL Kft
Made with Furo
Last updated on Jun 11, 2025
On this page
  • Drop-Down List (lv_dropdown)
    • Overview
    • Parts and Styles
      • Button
      • List
    • Usage
      • List items
      • Get selected option
      • Direction
      • Symbol
      • Show selected
      • Programmatically open/close
    • Events
    • Keys
    • Example
      • Simple Drop down list
      • Drop down in four directions
      • Menu
    • API