Hello to everyone who is reading this! I am trying to create a “Light Theme & Dark Theme” type extension. I have received help from well experienced people and I must thank you. I have progressed but the last piece to my puzzle is trying to change the background color of the screen when a button is pressed. Now I could just use “Set Screen1 Background Color to” and assign it to a button but I want the challenge. Post below is a snippet of my code so far.
~ CODE ~
package io.makeroid.jc1bryan_82242.TestingColor1;import com.google.appinventor.components.annotations.DesignerComponent;
import com.google.appinventor.components.annotations.DesignerProperty;
import com.google.appinventor.components.annotations.PropertyCategory;
import com.google.appinventor.components.annotations.SimpleEvent;
import com.google.appinventor.components.annotations.SimpleFunction;
import com.google.appinventor.components.annotations.SimpleObject;
import com.google.appinventor.components.annotations.SimpleProperty;
import com.google.appinventor.components.annotations.UsesPermissions;
import com.google.appinventor.components.common.ComponentCategory;
import com.google.appinventor.components.common.PropertyTypeConstants;
import com.google.appinventor.components.runtime.AndroidNonvisibleComponent;
import com.google.appinventor.components.runtime.ComponentContainer;
import com.google.appinventor.components.runtime.*;/* FOR BACKGROUND CHANGING
import android.app.Activity;
import android.widget.RelativeLayout;
import android.graphics.Color;
import android.view.View;
import android.os.Bundle;
import android.widget.Button;*/@DesignerComponent(
version = 1,
description = “Extension made with Kodular IDE”,
category = ComponentCategory.EXTENSION,
nonVisible = true,
iconName = “https://ide.kodular.io/assets/logo.png”)@SimpleObject(external = true)
public final class TestingColor1 extends AndroidNonvisibleComponent {//private Button button;
public TestingColor1(ComponentContainer container) {
super(container.$form());
}
/* Coming Soon
@DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_COMPONENT)
@SimpleProperty
public void Button(Button button) {
this.button = button;
// do additional stuff to configure button…
}*/// Purple Blocks are the function blocks. These blocks can only accept color blocks //
@SimpleFunction(description = “Sets Application to White”) // So this block would set the application to white //
public void SetLightTheme(int Color) {
// For this block I want the user to only set this block to “White” for now
}
@SimpleFunction(description = “Sets Application to Black”) // So this block would set the application to black //
public void SetDarkTheme(int Color) {
// For this block I want the user to only set this block to “Black” for now
}
@SimpleFunction(description = “Resets the apllication to default color”) // So this block would set the application to the default color //
public void SetDefaultColor(int Color) {
// For this block I want the user to only set this block to whatever the default background color was
}
}
Basically I have everything in a template for when the code goes in. I already have the these imported for changing background color. Posted below -----
import android.app.Activity;
import android.widget.RelativeLayout;
import android.graphics.Color;
import android.view.View;
import android.os.Bundle;
import android.widget.Button;
People keep saying its just like coding in java and so thats not a problem but every time I try typing java and implementing it into the code, errors seem to pile up.
So what im trying to understand is setting a function block to accepting 1 color, and when I press the button on the application, the background color will change to what I set it. For setting a background color, this is what I got so far —
setBackgroundColor(Color.parseColor("#01ff90"));
Thank you to those who helped me out so far. I greatly appreciate it. Im not begging or asking for code, just guidance because I want to learn the code without it being given to me all the time.