How to define themes in UsesActivities annotation?

Hi :slightly_smiling_face:,
I checked some open source extensions and found that we can use custom themes for actvities.
But I could not find way to write it.I mean how to correctly define it.
Can someone help ?

Thank you.

2 Likes

@vknow360 are you asking for an activity theme?

Yes

Okay wait let me find code because I created something like that but it was not working perfectly so that I had not published it.



import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.ContextThemeWrapper;
import com.google.appinventor.components.annotations.DesignerComponent;
import com.google.appinventor.components.annotations.SimpleFunction;
import com.google.appinventor.components.annotations.SimpleObject;
import com.google.appinventor.components.annotations.UsesPermissions;
import com.google.appinventor.components.common.ComponentCategory;
import com.google.appinventor.components.runtime.AndroidNonvisibleComponent;
import com.google.appinventor.components.runtime.Component;
import com.google.appinventor.components.runtime.ComponentContainer;

@DesignerComponent(
  version = 1,
  description = "",
  category = ComponentCategory.EXTENSION, 
  nonVisible = true, 
  iconName = "",
  helpUrl = "")
@SimpleObject(external = true)
@UsesPermissions(permissionNames = "")
public class AppTheme
  extends AndroidNonvisibleComponent
  implements Component
{
  private boolean mCancel;
  public static final int VERSION = 1;
  private ComponentContainer container;
  private Context context;
  private Activity Acty;
  private static final String LOG_TAG = "Theme";
  
  public AppTheme(ComponentContainer container) {
    super(container.$form());
    this.container = container;
    this.context = (Context)container.$context();
    Log.d("Theme", "Theme");
  }

  @SimpleFunction(description = "For Using This Extension Please See Documentation.")
  public void Overlay() 
  {
  this.Acty = (Activity)this.context;
  ContextThemeWrapper w = new ContextThemeWrapper(this.context, 16974407);
  this.context.getTheme().setTo(w.getTheme());
  }
  
  
  
  @SimpleFunction(description = "For Using This Extension Please See Documentation.")
  public void OverlayMaterial() 
  {
  this.Acty = (Activity)this.context;
  ContextThemeWrapper w = new ContextThemeWrapper(this.context, 16974408);
  this.context.getTheme().setTo(w.getTheme());
  }
  
  
  
  @SimpleFunction(description = "For Using This Extension Please See Documentation.")
  public void OverlayMaterialDark() 
  {
  this.Acty = (Activity)this.context;
  ContextThemeWrapper w = new ContextThemeWrapper(this.context, 16974411);
  this.context.getTheme().setTo(w.getTheme());
  }



@SimpleFunction(description = "For Using This Extension Please See Documentation.")
  public void OverlayMaterialLight() 
  {
  this.Acty = (Activity)this.context;
  ContextThemeWrapper w = new ContextThemeWrapper(this.context, 16974410);
  this.context.getTheme().setTo(w.getTheme());
  }
  
  
  
  @SimpleFunction(description = "For Using This Extension Please See Documentation.")
  public void Black() 
  {
  this.Acty = (Activity)this.context;
  ContextThemeWrapper w = new ContextThemeWrapper(this.context, 16973832);
  this.context.getTheme().setTo(w.getTheme());
  }
  
  @SimpleFunction(description = "For Using This Extension Please See Documentation.")
  public void DeviceDefault() 
  {
  this.Acty = (Activity)this.context;
  ContextThemeWrapper w = new ContextThemeWrapper(this.context, 16974120);
  this.context.getTheme().setTo(w.getTheme());
  }
  
  @SimpleFunction(description = "For Using This Extension Please See Documentation.")
  public void DeviceDefaultLight() 
  {
  this.Acty = (Activity)this.context;
  ContextThemeWrapper w = new ContextThemeWrapper(this.context, 16974123);
  this.context.getTheme().setTo(w.getTheme());
  }
  
  
  @SimpleFunction(description = "For Using This Extension Please See Documentation.")
  public void DeviceDefaultPanel() 
  {
  this.Acty = (Activity)this.context;
  ContextThemeWrapper w = new ContextThemeWrapper(this.context, 16974138);
  this.context.getTheme().setTo(w.getTheme());
  }
  
  @SimpleFunction(description = "For Using This Extension Please See Documentation.")
  public void Material() 
  {
  this.Acty = (Activity)this.context;
  ContextThemeWrapper w = new ContextThemeWrapper(this.context, 16974372);
  this.context.getTheme().setTo(w.getTheme());
  }
  
  
  
  @SimpleFunction(description = "For Using This Extension Please See Documentation.")
  public void MaterialLight() 
  {
  this.Acty = (Activity)this.context;
  ContextThemeWrapper w = new ContextThemeWrapper(this.context, 16974391);
  this.context.getTheme().setTo(w.getTheme());
  }
  
  
   @SimpleFunction(description = "For Using This Extension Please See Documentation.")
  public void MaterialLightPanel() 
  {
  this.Acty = (Activity)this.context;
  ContextThemeWrapper w = new ContextThemeWrapper(this.context, 16974405);
  this.context.getTheme().setTo(w.getTheme());
  }
  
  @SimpleFunction(description = "For Using This Extension Please See Documentation.")
  public void MaterialPanel() 
  {
  this.Acty = (Activity)this.context;
  ContextThemeWrapper w = new ContextThemeWrapper(this.context, 16974386);
  this.context.getTheme().setTo(w.getTheme());
  }

}


AppTheme.aix (6.6 KB)

1 Like

I think you misunderstood.
I was talking about something like this:

oo sorry because i think you are asking about app theme.

See the source for the Barcode Scanner component. It is used there.

@UsesActivities(activities = {

    @ActivityElement(name = "com.google.zxing.client.android.AppInvCaptureActivity", screenOrientation = "landscape", stateNotNeeded = "false", configChanges = "orientation|keyboardHidden", theme = "@android:style/Theme.NoTitleBar.Fullscreen", windowSoftInputMode = "stateAlwaysHidden")})
2 Likes

do you have any documentation about UsesActivites?

Not documentation but here is an example:

So where can I find out what UsesActivities is used for?

UsesActivities can be used to define custom activities in the AndroidManifest that are required when your extension is included in an app. You can learn more about all of the supported annotations in this document. Please note that because activities add information to the AndroidManifest, which is constant once compiled, extensions that use activities won't work in the companion (since its manifest doesn't contain your activity definition).

1 Like