Toast a message with a custom view in sketchware

1) Create a new Sketchware Project.

2) Add a new Custom view with name custom.

3) Add a more block customToast with a String text.

4) In that Moreblock add a ASD block and copy the below code:-
LayoutInflater inflater = getLayoutInflater();
View toastLayout = inflater.inflate(R.layout.custom, null);

TextView textview = (TextView) toastLayout.findViewById(R.id.textview1);
textview.setText(_text);
LinearLayout linear = (LinearLayout) toastLayout.findViewById(R.id.linear1);

Toast toast = new Toast(getApplicationContext()); toast.setDuration(Toast.LENGTH_SHORT);
toast.setView(toastLayout);
toast.show();

5) Go to the custom view then add a Linear Layout linear1 and a TextView textview1 inside it.

6) By using this moreblock customToast you can show custom toast.


Thank You...






In order to make the custom toast rounded replace the above code with this code:-

LayoutInflater inflater = getLayoutInflater();
View toastLayout = inflater.inflate(R.layout.custom, null);

TextView textview = (TextView) toastLayout.findViewById(R.id.textview1);
textview.setText(_text);
LinearLayout linear = (LinearLayout) toastLayout.findViewById(R.id.linear1);
android.graphics.drawable.GradientDrawable gd = new android.graphics.drawable.GradientDrawable();
gd.setColor(Color.parseColor("#00449a"));
gd.setCornerRadius(60);
gd.setStroke(2, Color.parseColor("#ff0000"));

linear.setBackground(gd);


Toast toast = new Toast(getApplicationContext()); toast.setDuration(Toast.LENGTH_SHORT);
toast.setView(toastLayout);
toast.show();


Again Thank you...

Comments

Popular posts from this blog

How to make a website in 2019 with no investment.

Make a layout with rounded corners in sketchware

Add menu in actionbar in Sketchware