How to change the Button outline color when it is focused

A blue outline appears when it is focused, I want to change the color. Some one know how to modify it?
Thanks very much!


Every LVGL object has set_style_.... functions, and those require also a “selector” as last argument.
In your case you need set_style_outline_color() function.

The “selector” can be a PART (lv.PART.…), and/or STATE (lv.STATE.…).
So you just need to pass the state “focused”:


You can quickly test it in LVGL MicroPython simulator:

Copy-paste this test code, hit “Restart”, then click on button:

# Initialize 
import display_driver
import lvgl as lv

# Create a button with a label 
scr = lv.obj()

btn = lv.btn(scr)
btn.align(lv.ALIGN.CENTER, 0, 0)
btn.set_style_outline_width(3, lv.STATE.DEFAULT)
btn.set_style_outline_color(lv.color_hex(0xFF0000), lv.STATE.DEFAULT)

# Set focused outline color
btn.set_style_outline_color(lv.color_black(), lv.STATE.FOCUSED)

label = lv.label(btn)
label.set_text('Hello World!')