android-toast

How can I show a toast for a specific duration?

大兔子大兔子 提交于 2019-11-28 04:33:52
This is the way I have to show the Toast for 500 milliseconds. Though, it's showing more than a second. Toast.makeText(LiveChat.this, "Typing", 500).show(); How can I show Toast only for 500 milliseconds? This cannot be done. To show a toast for a length shorter than Toast.LENGTH_SHORT , you must cancel it after the time you want. Something like: final Toast toast = Toast.makeText(getApplicationContext(), "This message will disappear in half a second", Toast.LENGTH_SHORT); toast.show(); Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { toast

Android progressBar setVisibility() not working

元气小坏坏 提交于 2019-11-28 02:24:16
Can someone please help me understand why progressBar.setVisibility() works when using a CountDownTimer but not when doing async download? In fact, the first Toast on async download does not even show even though the second one onPostExecute() does. Below is a working, or rather NOT working, demo. Thanks a lot. My MainActivity : public class MainActivity extends AppCompatActivity { ProgressBar progressBar; int[] items = { 12982418, 12998698, 12993549, 12995125, 12987537, 12993021, 12991986, 13008408, 12983417, 12986060, 12998395, 12985644, 13014731, 12986433, 12985074, 12994455, 12994262,

Simple Android toasts not aligning properly

穿精又带淫゛_ 提交于 2019-11-27 23:29:32
问题 I'm simply calling from my Activity : Toast.makeText(this, "This is a toast", Toast.LENGTH_SHORT).show() But the result is a text aligned on the top of the toast container, not centered inside as it should: Any ideas on what could be wrong? 回答1: I managed to fix it. The problem lies in applying the attribute android:fitsSystemWindows to the theme of an activity. I found this answer that explains why that should not be done: The android:fitsSystemWindows attribute is intended for usage on

How to avoid a Toast if there's one Toast already being shown

三世轮回 提交于 2019-11-27 20:24:05
I have several SeekBar and onSeekBarProgressStop() , I want to show a Toast message. But if on SeekBar I perform the action rapidly then UI thread somehow blocks and Toast message waits till UI thread is free. Now my concern is to avoid the new Toast message if the Toast message is already displaying. Or is their any condition by which we check that UI thread is currently free then I'll show the Toast message. I tried it in both way, by using runOnUIThread() and also creating new Handler . Addi I've tried a variety of things to do this. At first I tried using the cancel() , which had no effect

How to display Toast from a Service after main Activity finishes?

与世无争的帅哥 提交于 2019-11-27 13:09:56
问题 UPDATE: I don't agree that this is a duplicate - because I am seeking for a way to exit the main app and still show a Toast from the service. In a very simple test app I have 2 buttons: Clicking any of the buttons will run a service with a corresponding action string ("open" or "flash") - OpenActivity.java: public class OpenActivity extends Activity { private Intent mServiceIntent; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R

Adding image to Toast?

旧城冷巷雨未停 提交于 2019-11-27 10:27:35
Is it possible to programmatically add an image to a toast popup? Paresh Mayani Yes , you can add imageview or any view into the toast notification by using setView() method, using this method you can customize the Toast as per your requirement. Here i have created a Custom layout file to be inflated into the Toast notification, and then i have used this layout in Toast notification by using setView() method. cust_toast_layout.xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout

Android - Snackbar vs Toast - usage and difference

拈花ヽ惹草 提交于 2019-11-27 05:33:20
问题 We have been using just Toasts in our application so far and as we are planning to adopt some new features from Support Design Library I am wondering what's the recommended usage for Snackbar vs. Toast. I have been reading on the google material snackbar doc. Snackbars provide lightweight feedback about an operation in a small popup at the base of the screen on mobile and at the lower left on desktop. They are above all over elements on screen, including the FAB. and toasts. Android also

How to create toast from IntentService? It gets stuck on the screen

☆樱花仙子☆ 提交于 2019-11-27 01:47:59
问题 I'm trying to have my IntentService show a Toast message, but when sending it from the onHandleIntent message, the toast shows but gets stuck and the screen and never leaved. I'm guessing its because the onHandleIntent method does not happen on the main service thread, but how can I move it? Has anyone has this issue and solved it? 回答1: in onCreate() initialize a Handler and then post to it from your thread. private class DisplayToast implements Runnable{ String mText; public DisplayToast

Android progressBar setVisibility() not working

扶醉桌前 提交于 2019-11-26 23:45:56
问题 Can someone please help me understand why progressBar.setVisibility() works when using a CountDownTimer but not when doing async download? In fact, the first Toast on async download does not even show even though the second one onPostExecute() does. Below is a working, or rather NOT working, demo. Thanks a lot. My MainActivity : public class MainActivity extends AppCompatActivity { ProgressBar progressBar; int[] items = { 12982418, 12998698, 12993549, 12995125, 12987537, 12993021, 12991986,

How to avoid a Toast if there's one Toast already being shown

非 Y 不嫁゛ 提交于 2019-11-26 20:19:27
问题 I have several SeekBar and onSeekBarProgressStop() , I want to show a Toast message. But if on SeekBar I perform the action rapidly then UI thread somehow blocks and Toast message waits till UI thread is free. Now my concern is to avoid the new Toast message if the Toast message is already displaying. Or is their any condition by which we check that UI thread is currently free then I'll show the Toast message. I tried it in both way, by using runOnUIThread() and also creating new Handler .