android-toast

Adding image to Toast?

亡梦爱人 提交于 2019-11-26 15:10:42
问题 Is it possible to programmatically add an image to a toast popup? 回答1: 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=

Can an Android Toast be longer than Toast.LENGTH_LONG?

社会主义新天地 提交于 2019-11-26 01:26:52
问题 When using setDuration() for a Toast, is it possible to set a custom length or at least something longer than Toast.LENGTH_LONG ? 回答1: The values of LENGTH_SHORT and LENGTH_LONG are 0 and 1. This means they are treated as flags rather than actual durations so I don't think it will be possible to set the duration to anything other than these values. If you want to display a message to the user for longer, consider a Status Bar Notification. Status Bar Notifications can be programmatically

Android: Toast in a thread

瘦欲@ 提交于 2019-11-25 22:37:57
问题 How can I display Toast messages from a thread? 回答1: You can do it by calling an Activity 's runOnUiThread method from your thread: activity.runOnUiThread(new Runnable() { public void run() { Toast.makeText(activity, "Hello", Toast.LENGTH_SHORT).show(); } }); 回答2: I like to have a method in my activity called showToast which I can call from anywhere... public void showToast(final String toast) { runOnUiThread(() -> Toast.makeText(MyActivity.this, toast, Toast.LENGTH_SHORT).show()); } I then