Android -- Is there a way to rotate a toast 90 degrees? - android

Can't think of any more info to provide. Is there a way?

As hackbod said, you would have to have a custom view to display the toast.
I found a few classes for you that rotates the label for you: VerticalLabelView and CustomTextView
I chose to use the latter, and had this code working in my own app:
// Creating a new toast object
Toast myToast = new Toast(MyActivity.this);
// Creating our custom text view, and setting text/rotation
CustomTextView text = new CustomTextView(MyActivity.this);
text.SetText("Hello World!");
text.SetRotation(-90, 120, 90);
myToast.setView(text);
// Setting duration and displaying the toast
myToast.setDuration(Toast.LENGTH_SHORT);
myToast.show();

Not an easy way. You can supply your own view to display the toast, so you can make a view that rotates its content.

Related

Image icon within Toast maketext message

I am beginning learning some android mobile development and have created a notepad app through some tutorials and am now wanting to customise it a little.
I currently have a Toast maketext message that displays when a user saves a new note. The code is as follows:
if(Utilities.saveNote(this, new Note(mNoteCreationTime, title, content)))
Toast.makeText(this, "Swag Note has been saved", Toast.LENGTH_SHORT).show();
What I am wanting to do is add a small icon at both ends of this toast message.
Is there a relatively simple way of achieving this?
Toasts cannot have icons. You can create a custom Toast with ImageViews in it (example). However, there might be an unicode symbol that suits your purpose: in that case, you can just paste it.
Edit:
To make the linked example work, you'd just have to add a View for the image with id "toast_image", which will be invoked this way:
ImageView image = (ImageView) layout.findViewById(R.id.toast_image);
Show Toast as you do it now:
Toast.makeText(this, "Swag Note has been saved", Toast.LENGTH_SHORT).show();
Show MyToast from linked example:
MyToast.show(this, "Swag Note has been saved", false);

Android avoid closing Toast when click on it

This is how i show my Toast message.
Toast.makeText(getActivity(), "This is my Toast message!",Toast.LENGTH_LONG).show();
When i click on Toast it will disappear.
How can I avoid sudden disappear of Toast when i click on it.
Toast doesn't disappear for sudden clicks . , it will disappear on with duration u set
I suggest you to use Snackbar.
Snackbar has LENGTH_INDEFINITE attribute on the duration so I think it is pretty much what you wanted.
Toasts doesn't close on interactions it depends on the duration you set which are
LENGTH_SHORT and LENGTH_LONG are 0 and 1. If you want something that stays longer use actionbar notifications
Andorid Toast can be used to display information for the short period of time. A toast contains message to be displayed quickly and disappears after sometime.
You can also create custom toast as well
//Creating the LayoutInflater instance
LayoutInflater li = getLayoutInflater();
//Getting the View object as defined in the customtoast.xml file
View layout = li.inflate(R.layout.customtoast,
(ViewGroup) findViewById(R.id.custom_toast_layout));
//Creating the Toast object
Toast toast = new Toast(getApplicationContext());
toast.setDuration(Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.setView(layout);//setting the view of custom toast layout
toast.show();
OR ..
Toast toast=Toast.makeText(getApplicationContext(),"Hello Javatpoint",Toast.LENGTH_SHORT);
toast.setMargin(50,50);
toast.show();
You can use the for loops for duration

Animating a toast in android?

Am trying to animate my toast but have been unsuccessful so far. This is what I have in my onCreate():
ImageView image = new ImageView(this);
image.setImageResource(R.drawable.icon);
Animation move = new TranslateAnimation(0,100, 0, 100);
move.setDuration(2000);
move.setFillEnabled(true);
move.setFillAfter(true);
image.startAnimation(move);
Toast toast = new Toast(this);
toast.setView(image);
toast.show();
Have tried placing startAnimation() after displaying the toast, but that doesn't work either.
Toast notifications use a system template to determine how they are displayed. Short of modifying the Android source code, you can not create a special animation for your Toast message.
However, if possible you might be able to create a normal view and use that instead. One common method is to create a new Activity that has a transparent background with your modal toast message animated and displayed however you want.

Android App - How to Set OpenFeint Notification Position

I've Integrated OpenFeint in my android game but the score-post and achievement unlock notification is shown at bottom of the screen automatically.
how can i manually set the location of the that notification on my screen.? I want to show it to the top of the screen.
The OpenFeint sample code uses the Toast Class to display those notifications. You can easily adjust that code to almost anything you want.
edit: I realize that you might mean the notification that comes from the bottom, in which case you will need to write a class extending com.openfeint.api.Notification.Delegate and display your own design. Unfortunately OpenFeint doesnt provide parameters on the default notification class.
You can easily show it at the top of the screen by editing the NotificationBase.java file. It is located in com.openfeint.internal.notifications. Just look for the showToast() method, and edit it. Change Gravity.BOTTOM to Gravity.TOP. Check it out below:
protected void showToast() {
OpenFeintInternal.getInstance().runOnUiThread(new Runnable() {
#Override
public void run() {
Context appContext = OpenFeintInternal.getInstance().getContext();
toast = new Toast(appContext);
toast.setGravity(Gravity.TOP, 0, 0);
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(displayView);
toast.show();
}
});
}

How to check which image is set to the activity's view?

How can I check what image is on my activity (programmatically)? I want to make a condition: if I have lets say img1, then I want to show a Toast "img1", and if I have img2, then I want to show a Toast "img2". I know there is something like setImageDrawable(getResources().getDrawable(R.drawable.img2), which does setting an image.
you can use the setTag function associated with a view to hold this information, as in view.setTag("img1") and you can get back the value as in (String)view.getTag()
you want to test if your imageView contains an image, then u want to set another
use this if it helps
if(imgView.getDrawable().equals(this.getResources().getDrawable(R.id.img1))) {
//affiche your Toast Here ... Toast ( "img1 displayed ..").show();
Toast.makeText(this,"image 1 dispayed ...",3000).show();
}
else if(imgView.getDrawable().equals(this.getResources().getDrawable(R.id.img2))) {
//affiche your Toast Here ... Toast ( "img2 displayed ..").show();
Toast.makeText(this,"image 2 dispayed ...",3000).show();
}
is that what you want to do ??

Categories

Resources