Extension creating doubt

i am new to this community just 1-2 weeks ago i came to this community but i am developing 3 apps for a year,i actually want to learn a bit off java,to develop extension.

before starting with my question i would like to thank this wonderfull conversation

Getting error in extension building - Extension Development - MIT App Inventor Community

from where i developed the code a bit
after reffering from android studio
at this para it says the code for positioning:- click here

i made the code with gravity and a new pakage imported

import android.content.Context;
import android.util.Log;
import com.google.appinventor.components.annotations.;
import com.google.appinventor.components.runtime.
;
import com.google.appinventor.components.annotations.DesignerComponent;
import com.google.appinventor.components.annotations.SimpleObject;
import com.google.appinventor.components.annotations.SimpleFunction;
import com.google.appinventor.components.annotations.SimpleEvent;
import com.google.appinventor.components.annotations.SimpleProperty;
import com.google.appinventor.components.common.ComponentCategory;
import com.google.appinventor.components.runtime.AndroidNonvisibleComponent;
import com.google.appinventor.components.runtime.AndroidViewComponent;
import com.google.appinventor.components.runtime.ComponentContainer;
import com.google.appinventor.components.runtime.EventDispatcher;
import android.widget.Toast;
import android.content.Context;
import android.view.Gravity;

@DesignerComponent(version = 1, description = “This Extension was created with the AppyBuilder Code Editor.
” +
“Create your own here:
https://editor.appybuilder.com
”,
category = ComponentCategory.EXTENSION,
nonVisible = true, iconName = “http://appyBuilder.com/extensions/icons/extension.png”)
@SimpleObject(external = true)
public class Simple_toast extends AndroidNonvisibleComponent {
private ComponentContainer container;
/**
* @param container container, component will be placed in
*/
public Simple_toast(ComponentContainer container) {
super(container.$form());
this.container = container;
}

@SimpleFunction(description = “Show toast message,give xaxis,yaxis,message”)
public void ShowToastMessage(String message, int x, int y) {
//YOUR ACTIVITY HERE
Toast toast = Toast.makeText(container.$context(),message,Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER, x, y);
toast.show();
}
@SimpleFunction(description = “Show toast message,give message”)
public void ShowsimpleToastMessage(String message) {
//YOUR ACTIVITY HERE
Toast toast1 = Toast.makeText(container.$context(),message,Toast.LENGTH_SHORT);
toast1.show();
}
}

later i want to add the background colour ,text colour,custom toast (image+text)
but here i have a problem i neither know the packages name i need to import nor the code
so here i need your help

can some one solve the issue

these to web page i referred

and i think the answer is there
but still i dont understand how to implement it in my app

what is the error and what you want ??

i want to add the background colour ,text colour,custom toast (image+text)to my toast
but here i have a problem i neither know the packages name i need to import nor the code
so here i need your help

can some one solve the issue

these to web page i referred

Android Examples – 1 Dec 15

Change Toast message background color in android - Android Examples

Change Toast message background color in android.Set different background color and modify toast using xml view programmatically.setBackgroundResource.

stackoverflow.com

Saranya

How can i change default toast message color and background color in android?

android, android-toast

asked by Saranya on 04:27AM - 02 Jul 15 UTC

and i think the answer is there
but still i dont understand how to implement it in my app

To change the Background color use this code.

Toast toast = Toast.makeText(context, Message, Toast.LENGTH_LONG);   
toast.getView().setBackgroundColor(Color.TRANSPARENT);
toast.show();

Imports you need

import android.view.View;
import android.widget.Toast;

thanking you a lot i will try ,i will credit you always my friend :star_struck:

but but :cry:

i coded this @AryanGupta

import android.content.Context;
import android.util.Log;
import com.google.appinventor.components.annotations.;
import com.google.appinventor.components.runtime.
;
import com.google.appinventor.components.annotations.DesignerComponent;
import com.google.appinventor.components.annotations.SimpleObject;
import com.google.appinventor.components.annotations.SimpleFunction;
import com.google.appinventor.components.annotations.SimpleEvent;
import com.google.appinventor.components.annotations.SimpleProperty;
import com.google.appinventor.components.common.ComponentCategory;
import com.google.appinventor.components.runtime.AndroidNonvisibleComponent;
import com.google.appinventor.components.runtime.AndroidViewComponent;
import com.google.appinventor.components.runtime.ComponentContainer;
import com.google.appinventor.components.runtime.EventDispatcher;
import android.widget.Toast;
import android.view.View;
import android.content.Context;
import android.view.Gravity;

@DesignerComponent(version = 1, description = “This Extension was created with the AppyBuilder Code Editor.
” +
“Create your own here:
https://editor.appybuilder.com
”,
category = ComponentCategory.EXTENSION,
nonVisible = true, iconName = “http://appyBuilder.com/extensions/icons/extension.png”)
@SimpleObject(external = true)
public class Simple_toast extends AndroidNonvisibleComponent {
private ComponentContainer container;
/**
* @param container container, component will be placed in
*/
public Simple_toast(ComponentContainer container) {
super(container.$form());
this.container = container;
}

@SimpleFunction(description = “Show toast message,give xaxis,yaxis,message”)
public void ShowToastMessage(String message, int x, int y) {
//YOUR ACTIVITY HERE
Toast toast = Toast.makeText(container.$context(),message,Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER, x, y);
toast.getView().setBackgroundColor(Color.TRANSPARENT);
toast.show();
}
}

i did this in appy builder and got this

my error.txt (4.0 KB)
help please

You will need to import the Color class as well:
android.graphics.Color.
As you are using one if its enums/constants here:

Note: for questions about extension development, you should ask in the app Inventor community:


The #discuss category is for discussion about kodular.
Thanks.

thanks a lot

1 Like

can i create this topic there and delete here

please follow the naming conventions


Taifun

i am getting this error
err

it is a code not a error

any way i aldready did this coding you can find all here

(post withdrawn by author, will be automatically deleted in 24 hours unless flagged)

ads are not relevant to this topic post it in new topic its not relevant to toast

I think your compiler doesn’t support Android imports

so, what should i do?

The code is for extension ?? If yes, then don’t worry it will work in extensions.

when i am compiling it shows package does not exist

How you compile the code ?? Do not compile the code in your compiler . Just copy the code and paste it in a new notepad java file and then, save the file to your package. After that you can run ant extensions in Apache ant

1 Like