Hi,
I added in MainView.java the code to change theme variant from Light in Dark and revers but I have two questions:
1.What icon is used with half circle empty and half full for this button in the page https://demo.jmix.io/ui-samples/ for this task, now I use full circle themeButton.setIcon(VaadinIcon.CIRCLE.create());
;
2. How I can place the button at the end on right of header?
Code used, may help someone:
package com.genebank.genedatabank.view.main;
import com.vaadin.flow.component.UI;
import com.vaadin.flow.component.button.ButtonVariant;
import com.vaadin.flow.component.html.Header;
import com.vaadin.flow.component.icon.VaadinIcon;
import com.vaadin.flow.dom.ThemeList;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.theme.lumo.Lumo;
import io.jmix.flowui.UiComponents;
import io.jmix.flowui.app.main.StandardMainView;
import io.jmix.flowui.kit.component.button.JmixButton;
import io.jmix.flowui.view.*;
import org.springframework.beans.factory.annotation.Autowired;
@Route("")
@ViewController("MainView")
@ViewDescriptor("main-view.xml")
public class MainView extends StandardMainView {
@Autowired
private UiComponents uiComponents;
@ViewComponent
private MessageBundle messageBundle;
@ViewComponent
private Header header;
@Subscribe
public void onInit(final InitEvent event) {
initManualThemeChange();
}
protected void initManualThemeChange() {
JmixButton themeChangeButton = createThemeButton();
themeChangeButton.addClickListener(e -> {
ThemeList themeList = UI.getCurrent().getElement().getThemeList();
if (themeList.contains(Lumo.DARK)) {
themeList.remove(Lumo.DARK);
} else {
themeList.add(Lumo.DARK);
}
});
header.addComponentAsFirst(themeChangeButton);
}
protected JmixButton createThemeButton() {
JmixButton themeButton = uiComponents.create(JmixButton.class);
themeButton.setIcon(VaadinIcon.CIRCLE.create());
themeButton.addThemeVariants(ButtonVariant.LUMO_ICON, ButtonVariant.LUMO_TERTIARY_INLINE);
String toolTipThemeButton = messageBundle.getMessage("toolTipThemeButtonMessage");
themeButton.setTooltipText(toolTipThemeButton);
return themeButton;
}
}
Light
Dark