You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Please offer something that mimics the standard Toast's look&feel, so that at least we could have it shown within the app, as a normal View.
Maybe something similar to what we have when we long press the action items on the toolbar:
How did you fix it?
Have you implemented a custom View for Toast, that isn't really a Toast, and shown only inside the app itself?
I have used a PopupWindow with a custom view inside. I did some research and it seems to be the best option, because unfortunately it is no longer possible to use a custom view in a Toast.
@marcoscgdev
It might be possible using reflection, but it's a path I wouldn't recommend, especially now that Google tries to protect vs such things...
Anyway, thank you for this.
Is it possible to use your solution to position it near a View, like what we see when we long press an action-item of a Toolbar (which shows explanation of what it is) ?
@marcoscgdev
It might be possible using reflection, but it's a path I wouldn't recommend, especially now that Google tries to protect vs such things...
Anyway, thank you for this.
Is it possible to use your solution to position it near a View, like what we see when we long press an action-item of a Toolbar (which shows explanation of what it is) ?
At this time it is not possible to do that. However, I will work on it for future versions 👌
@marcoscgdev Does it get positioned nicely? Even if the view is at the corner?
Can you please let me know when this feature is ready?
Yes, apparently it fits the view well. I don't know when I'm going to release a new version, but I've just make a commit with these changes and you can try them out in this non-definitive version:
@marcoscgdev Can you please show a snippet, of how to show your toast for some View? Something similar to what we see when we long press the action-item of a toolbar?
@marcoscgdev Can you please show a snippet, of how to show your toast for some View? Something similar to what we see when we long press the action-item of a toolbar?
Sure. Just call show(yourView).
Ful example:
MaterialToast.makeText(activity, "Hello, I'm a material toast!", R.mipmap.ic_launcher, Toast.LENGTH_SHORT).show(yourView)
or
MaterialToast(this)
.setMessage("Hello, I'm a material toast!")
.setIcon(R.mipmap.ic_launcher)
.setDuration(Toast.LENGTH_SHORT)
.setBackgroundColor(Color.RED)
.show(yourView)
If you want to show it on long click listener:
yourView.setOnLongClickListener {
MaterialToast.makeText(activity, "Hello, I'm a material toast!", R.mipmap.ic_launcher, Toast.LENGTH_SHORT).show(yourView)
true
}
@marcoscgdev Either I don't understand how to use it, or it doesn't exist.
See:
Please show how to use it.
I have explained to you before how it works. Your code in "My Application.zip" project is OK. I have tested it and it works. When you click on the button, the Toast will appear next to it.
@marcoscgdev I can't find "positionToast" anywhere.
Using my sample, I can't find how far I want the Toast to be (say, at least 12dp, for example) from the View.
Maybe you added it in a different name?
@marcoscgdev I can't find "positionToast" anywhere.
Using my sample, I can't find how far I want the Toast to be (say, at least 12dp, for example) from the View.
Maybe you added it in a different name?
@marcoscgdev
I've now tested it. Not sure how to set the positions properly.
If you've used the same code I wrote, note that I just copied it from somewhere else, and I don't think it should be up to the library to position it this way
The custom View works fine though.
Can you please set it to be to (0,0) by default, so that the toast x,y will be positioned exactly on the same x,y of the target View?
Maybe let whoever uses it to decide how to put it.
Maybe on the sample you can demonstrate how to do it nicely (like checking where the target View is, and based on this to decide where to put the Toast) .
See attached. It seems that if the target View is at the bottom right, it puts the toast on center-horizontal of them, and sets the Y to be a bit above the target View:
Activity
marcoscgdev commentedon Dec 3, 2020
Fixed in version 1.0.2. Thank you! 👍
AndroidDeveloperLB commentedon Dec 3, 2020
How did you fix it?
Have you implemented a custom View for Toast, that isn't really a Toast, and shown only inside the app itself?
marcoscgdev commentedon Dec 4, 2020
I have used a PopupWindow with a custom view inside. I did some research and it seems to be the best option, because unfortunately it is no longer possible to use a custom view in a Toast.
AndroidDeveloperLB commentedon Dec 4, 2020
@marcoscgdev
It might be possible using reflection, but it's a path I wouldn't recommend, especially now that Google tries to protect vs such things...
Anyway, thank you for this.
Is it possible to use your solution to position it near a View, like what we see when we long press an action-item of a Toolbar (which shows explanation of what it is) ?
marcoscgdev commentedon Dec 4, 2020
At this time it is not possible to do that. However, I will work on it for future versions 👌
AndroidDeveloperLB commentedon Dec 5, 2020
@marcoscgdev Well if you have a custom view now, you can try using something like what was used for toast, at least as offered by others:
It might have some bug though. I haven't tested it much.
marcoscgdev commentedon Dec 5, 2020
This is very easy to do with PopupWindow. Simply call this method to display the alert next to a view:
popupWindow.showAsDropDown(yourView)This feature, along with code migration to Kotlin will be available in the next release.
AndroidDeveloperLB commentedon Dec 5, 2020
@marcoscgdev Does it get positioned nicely? Even if the view is at the corner?
Can you please let me know when this feature is ready?
marcoscgdev commentedon Dec 5, 2020
Yes, apparently it fits the view well. I don't know when I'm going to release a new version, but I've just make a commit with these changes and you can try them out in this non-definitive version:
implementation 'com.github.marcoscgdev:MaterialToast:b7a2bab65b'Tell me if everything works fine for you 😄
AndroidDeveloperLB commentedon Dec 5, 2020
@marcoscgdev Can you please show a snippet, of how to show your toast for some View? Something similar to what we see when we long press the action-item of a toolbar?
marcoscgdev commentedon Dec 5, 2020
Sure. Just call
show(yourView).Ful example:
or
If you want to show it on long click listener:
AndroidDeveloperLB commentedon Dec 6, 2020
@marcoscgdev I failed to use it this way. See attached. It doesn't do anything...
My Application.zip
marcoscgdev commentedon Dec 6, 2020
The Toast is always displayed below the view, so if the view is at the bottom of the screen, the Toast will not be displayed.
I have implemented this approach. Please try with this version:
implementation 'com.github.marcoscgdev:MaterialToast:e128609003'AndroidDeveloperLB commentedon Dec 6, 2020
@marcoscgdev I don't get how to use it.
It doesn't show up. I don't think this function exists.
marcoscgdev commentedon Dec 6, 2020
Of course this function exists, I have created it! 😄 You can check it here.
If you run your project using the latest version I left you in the previous message, it should work.
implementation 'com.github.marcoscgdev:MaterialToast:e128609003'AndroidDeveloperLB commentedon Dec 6, 2020
@marcoscgdev Either I don't understand how to use it, or it doesn't exist.
See:
Please show how to use it.
marcoscgdev commentedon Dec 7, 2020
I have explained to you before how it works. Your code in "My Application.zip" project is OK. I have tested it and it works. When you click on the button, the Toast will appear next to it.
AndroidDeveloperLB commentedon Dec 7, 2020
@marcoscgdev I can't find "positionToast" anywhere.
Using my sample, I can't find how far I want the Toast to be (say, at least 12dp, for example) from the View.
Maybe you added it in a different name?
See:
Attached new project:
My Application.zip
marcoscgdev commentedon Dec 7, 2020
I have not added the possibility of changing the distance to the view. The distance is always fixed, it only depends on the position of the view.
AndroidDeveloperLB commentedon Dec 7, 2020
@marcoscgdev Can you please add it, or at least make it have the same look&feel like the one of Google, a bit far ?
See here when you long press a Toolbar action item when it's at the top:
And this is when I put it at the bottom:
marcoscgdev commentedon Dec 8, 2020
View offset has been added. Here are some examples:
implementation 'com.github.marcoscgdev:MaterialToast:9e0879bdd7'AndroidDeveloperLB commentedon Dec 9, 2020
@marcoscgdev
I've now tested it. Not sure how to set the positions properly.
If you've used the same code I wrote, note that I just copied it from somewhere else, and I don't think it should be up to the library to position it this way
The custom View works fine though.
Can you please set it to be to (0,0) by default, so that the toast x,y will be positioned exactly on the same x,y of the target View?
Maybe let whoever uses it to decide how to put it.
Maybe on the sample you can demonstrate how to do it nicely (like checking where the target View is, and based on this to decide where to put the Toast) .
See attached. It seems that if the target View is at the bottom right, it puts the toast on center-horizontal of them, and sets the Y to be a bit above the target View:
My Application.zip
AndroidDeveloperLB commentedon Dec 9, 2020
I think this is nicer (when using a real Toast) about the auto-location (but again, should be optional to have it auto-position) :