Remove fade animation from toast message - android

I am using a hack to display an overlay over a picture in Google TV using a constant toast message.
I would like to know if there is a way to further modify the toast to remove the fade in and fade out effect. Ideally I would like the overlay to appear instantly.
Any help or direction would be greatly appreciated.

For this , i suggest we can use a layout(FrameLayout).
and by using a new layout above your current layout and adding view that looks similar to TOAST to the top layer
After that do one thing by making object of View as v
eg:-
View v;
v.setVisiblity(GONE);
v.setVisibility(VISIBLE);
This will make your view appear or hide.

You can use a FrameLayout and create a new Layout layer above your current layout and add a view that looks like toast to the top layer.
Then you can use: View.setVisiblity(GONE); and View.setVisibility(VISIBLE);
to make your view appear and hide instantly.
View.setVisibility Documentation
FrameLayout example

I like a fade-in effect, but I was in need to cancel a toast message immediately without fade-out effect, since the toast message remained shown for a short moment even when the Activity was already exited.
I came to this solution to close (or actually hide) my toast message t immediately:
((TextView)t.getView().findViewById(android.R.id.message)).setTextColor(Color.TRANSPARENT);
t.setText("");
t.getView().setBackgroundColor(Color.TRANSPARENT);
t.cancel();
I assume to set colors transparent is the only way to hide the fade effect with standard Toast layout.

Related

How to anchor a toast to a view, without overlapping them?

Background
Popups can be anchored to views, but the Toast is missing this API.
What I'd like to know, is how to correctly position a toast near a view (suppose prefer to put below if on upper half of screen, and above if on bottom half), so that they won't overlap each other, no matter the position&size of the view (unless really impossible because the view takes too much space, of course).
The problem
I'm aware there are various questions to this question, but all set the toast to be shown below the view, or manually set its position, without regard to the size of both of them.
What I've found
Currently I've found the next solutions:
here, it doesn't take the size of the toast into consideration
here, it lets you set the position of the toast manually, so they can still overlap each other.
It could be, however, that the toast that appears from long clicking an action item is anchored to the action item's view, but I didn't find out how it works there.
I've also tried many libraries from Android-Arsenal website, but all of them are either for styling the toasts, or make things that aren't toasts and sometimes don't even work well.
The question
Is there a generic way to use the same method used for Popups, on Toasts, so that it will be anchored to a view, without overlapping it?
You can set gravity for Toast in android like this
Toast toast = Toast.makeText(test.this,"bbb", Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
and rather play around giving int values. like
toast.setGravity(5,6,5);
and also try other values..
Another way is, you should create a custom toast like view under a layout
check this library
https://github.com/sephiroth74/android-target-tooltip

Create blue "tutorial" dialogs as in Android 4.4

I would like to create some "dialogs" like those shown in Android 4.4 for example when you are first shown immersive mode. The little arrow is important for me because I would like to have the dialogin different places on the screen.
This is what I'm talking about:
Do I need to create a custom AlertDialog? How do I move it around, can I use the coordinates of a View? I don't really know where to start. Are there any examples on creating this type of thing? I am not interested in using the ShowcaseView library as in my opinion has the "old" holo look.
You can get the coordinate of views using getLocationOnScreen(), make sure to call this after the views have been inflated (so, not in onCreate() of your activity) or else you will be returned default int values (i.e. 0).
You should probably create your own DialogFragment. Incorporate your own custom layout which contains the little bubble and the button. A Quick and dirty sample for the onCreateDialog() would have the following
Dialog dialog = new Dialog(getActivity());
// Get rid of the annoying alert dialog title bar
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
// You must set the content view after requesting window features, not before.
dialog.setContentView(someView);
// Make the dialog full screen
dialog.getWindow().setLayout(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
//Dim the background
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.argb(80, 0, 0, 0));
To incorporate the little arrow, you can try having variations of 9-patch images as the background of the little bubble. Another alternative would be to have an arrowhead and a bubble put into the same container, and setting the margin/padding between them to 0. Since you have the coordinates you can adjust the horizontal margins of the arrowhead accordingly. This is actually a pretty cool idea, I think I'll try my own interpretation of it this weekend.
I have actually been working on my own interpretation of the showcase library, Here is what i achieved. Much of the dynamic position changing should be the same I would think

Custom animation for Toast enter/exit?

I want to have my Toast's entrance and exit animations customized. Specifically, I want to make it appear instantly (no fade-in) and disappear like normal (fade-out).
Is there a way I can use animations with a toast?
Toasts are displayed using a system template that can't be changed so short answer is no you cant change the toast animation.
however you can make your own view that resembles a toast and animate it however you want.
It is not possible to do this with the stock Android Toast class. The Toast class is limited to four system animations and will not accept animations from your project.
See: Android add custom animation to Toast

How to create a dialog or popup which fades out?

I want to create a popup/dialog which appears at the bottom left of my screen (my activity) and which fades out after a certain amount of time similar to a Toast, but such that it is more complex than a Toast in that it has its own layout (images etc). Anyone know whether this is possible with DialogFragment or PopupWindow or any other class? And, if so, which class might be best for this kind of requirement?
You could create a Toast with a custom view: http://developer.android.com/guide/topics/ui/notifiers/toasts.html

Android - popup window or something else

I am currently developing an android app that displays a list view. When an item from the list view is selected I would like a small window to appear from the bottom of the screen. This window will not cover the entire list view, but take up a small portion of the bottom. On this window will be a few buttons and a progress bar.
My question is would the best way to achieve this be through a popupwindow or is there something else to better suit this?
Thank you for your help.
you could use a Dialog with a custom View (Android Custom Dialog example). Or you can forgo the concept of the pop-up and just "fake it" by adding your "pop-up" View into your normal layout but setting it as invisible. Then when you want to show it make it Visible and populate it with the appropriate data.
I think I understood what you meant. Do you use ActionBarSherkock? If yes, then there is a splitactionbar which is ususally located on the bottom of the screen, when the screen is small. It looks like this:
http://wptrafficanalyzer.in/blog/wp-content/uploads/2012/07/actionbar_menu_sherlock_splitactionbar.png
Is this what you meant? Let me please know.
Edit:
There is something called quick actions. This handels popups very well, but its not displayed on the bottom of the screen tough. But you might want to look at it:
http://londatiga.net/images/quickactions/quickcontact.jpg

Categories

Resources