I am working on an extension and need to switch activities using a class name. I want to know if it’s possible to use a screen in Kodular as an Android activity. How can I activate a screen by its class name? Can this be done using intents? If so, what is the correct approach?
Also, how to disable the default transition/Animation after starting the screen.
Any guidance or example blocks would be really helpful!
@iamwsumit @Still-learning
One more thing Can we modify layout xml file by using java code
suppose ,add new properity like android:text="Hello, I am a TextView" />
how can we do that by java
@SimpleFunction(description = "Sets the text of a TextView")
public void SetTextViewText(AndroidViewComponent component, String text) {
View view = component.getView();
if (view instanceof TextView) {
TextView textView = (TextView) view;
textView.setText(text);
} else {
// Handle error - component is not a TextView
throw new IllegalArgumentException("Component is not a TextView");
}
}
Method to modify textview properties
@SimpleFunction(description = "Sets the text size of a TextView")
public void SetTextViewSize(AndroidViewComponent component, int size) {
View view = component.getView();
if (view instanceof TextView) {
TextView textView = (TextView) view;
textView.setTextSize(size);
} else {
throw new IllegalArgumentException("Component is not a TextView");
}
}
@SimpleFunction(description = "Sets the text color of a TextView")
public void SetTextViewColor(AndroidViewComponent component, int color) {
View view = component.getView();
if (view instanceof TextView) {
TextView textView = (TextView) view;
textView.setTextColor(color);
} else {
throw new IllegalArgumentException("Component is not a TextView");
}
}
Method to add new textview in the layout
@SimpleFunction(description = "Adds a new TextView to a layout component")
public void AddTextViewToLayout(AndroidViewComponent layoutComponent, String text) {
View view = layoutComponent.getView();
if (view instanceof ViewGroup) {
ViewGroup layout = (ViewGroup) view;
// Create a new TextView
TextView newTextView = new TextView(context);
newTextView.setText(text);
// Set layout parameters
ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT
);
// Add the TextView to the layout
layout.addView(newTextView, params);
} else {
throw new IllegalArgumentException("Component is not a layout");
}
}
These three logic only i have used in my DynamicCalendar extension
Complex one. Find textview by ID
@SimpleFunction(description = "Sets the text of a TextView with the given ID")
public void SetTextViewTextById(AndroidViewComponent component, int viewId, String text) {
View parentView = component.getView();
// Find the TextView by ID in the component's view hierarchy
TextView textView = (TextView) parentView.findViewById(viewId);
if (textView != null) {
// Set the text property
textView.setText(text);
} else {
throw new IllegalArgumentException("TextView with ID " + viewId + " not found");
}
}