在应用程序中我希望给出更改主题的可能性,但如果我刷新页面它将回到默认主题我不知道如何为所有应用程序保存主题,有人可以帮助我吗?
import com.vaadin.ui.ComboBox;
import com.vaadin.ui.CustomComponent;
public class ThemeSelectorComboBox extends CustomComponent
{
private static final String SELECT_THEME = "Select theme:";
private final ComboBox<CustomTheme> comboBox = new ComboBox<>();
public ThemeSelectorComboBox()
{
init();
}
private void init()
{
comboBox.setCaption(SELECT_THEME);
comboBox.setItems(CustomTheme.values());
comboBox.setSelectedItem(CustomTheme.MATERIAL_DARK);
comboBox.addValueChangeListener(event -> flipTheme(event.getValue()));
setCompositionRoot(comboBox);
// Set the size as undefined at all levels
comboBox.setSizeUndefined();
setSizeUndefined();
}
private void flipTheme(CustomTheme theme)
{
if (theme != null)
{
getCompositionRoot().getUI().setTheme(theme.getThemeName());
}
}
}
答案 0 :(得分:2)
默认情况下,Vaadin在浏览器重新加载时执行UI.init,重置主题。你基本上有两个选择: