Java Code Examples for android.widget.Toast#getView()
The following examples show how to use
android.widget.Toast#getView() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Utils.java From ShadowsocksRR with Apache License 2.0 | 6 votes |
/** * round or floor depending on whether you are using offsets(floor) or * widths(round) * <p> * Based on: http://stackoverflow.com/a/21026866/2245107 */ public static Toast positionToast(Toast toast, View view, Window window, int offsetX, int offsetY) { Rect rect = new Rect(); window.getDecorView().getWindowVisibleDisplayFrame(rect); int[] viewLocation = new int[2]; view.getLocationInWindow(viewLocation); DisplayMetrics metrics = new DisplayMetrics(); window.getWindowManager().getDefaultDisplay().getMetrics(metrics); View toastView = toast.getView(); toastView.measure(View.MeasureSpec.makeMeasureSpec(metrics.widthPixels, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(metrics.heightPixels, View.MeasureSpec.UNSPECIFIED)); toast.setGravity(Gravity.LEFT | Gravity.TOP, viewLocation[0] - rect.left + (view.getWidth() - toast.getView().getMeasuredWidth()) / 2 + offsetX, viewLocation[1] - rect.top + view.getHeight() + offsetY); return toast; }
Example 2
Source File: Utils.java From Maying with Apache License 2.0 | 6 votes |
/** * round or floor depending on whether you are using offsets(floor) or * widths(round) * <p> * Based on: http://stackoverflow.com/a/21026866/2245107 */ public static Toast positionToast(Toast toast, View view, Window window, int offsetX, int offsetY) { Rect rect = new Rect(); window.getDecorView().getWindowVisibleDisplayFrame(rect); int[] viewLocation = new int[2]; view.getLocationInWindow(viewLocation); DisplayMetrics metrics = new DisplayMetrics(); window.getWindowManager().getDefaultDisplay().getMetrics(metrics); View toastView = toast.getView(); toastView.measure(View.MeasureSpec.makeMeasureSpec(metrics.widthPixels, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(metrics.heightPixels, View.MeasureSpec.UNSPECIFIED)); toast.setGravity(Gravity.LEFT | Gravity.TOP, viewLocation[0] - rect.left + (view.getWidth() - toast.getView().getMeasuredWidth()) / 2 + offsetX, viewLocation[1] - rect.top + view.getHeight() + offsetY); return toast; }
Example 3
Source File: ImageActivity.java From letv with Apache License 2.0 | 6 votes |
private void b(String str, int i) { Toast makeText = Toast.makeText(this, str, 1); LinearLayout linearLayout = (LinearLayout) makeText.getView(); ((TextView) linearLayout.getChildAt(0)).setPadding(8, 0, 0, 0); View imageView = new ImageView(this); imageView.setLayoutParams(new LinearLayout.LayoutParams(a.a(this, 16.0f), a.a(this, 16.0f))); if (i == 0) { imageView.setImageDrawable(b("com.tencent.plus.ic_success.png")); } else { imageView.setImageDrawable(b("com.tencent.plus.ic_error.png")); } linearLayout.addView(imageView, 0); linearLayout.setOrientation(0); linearLayout.setGravity(17); makeText.setView(linearLayout); makeText.setGravity(17, 0, 0); makeText.show(); }
Example 4
Source File: ImageActivity.java From MiBandDecompiled with Apache License 2.0 | 6 votes |
private void b(String s1, int i1) { Toast toast = Toast.makeText(this, s1, 1); LinearLayout linearlayout = (LinearLayout)toast.getView(); ((TextView)linearlayout.getChildAt(0)).setPadding(8, 0, 0, 0); ImageView imageview = new ImageView(this); imageview.setLayoutParams(new android.widget.LinearLayout.LayoutParams(com.tencent.connect.avatar.c.a(this, 16F), com.tencent.connect.avatar.c.a(this, 16F))); if (i1 == 0) { imageview.setImageDrawable(b("com.tencent.plus.ic_success.png")); } else { imageview.setImageDrawable(b("com.tencent.plus.ic_error.png")); } linearlayout.addView(imageview, 0); linearlayout.setOrientation(0); linearlayout.setGravity(17); toast.setView(linearlayout); toast.setGravity(17, 0, 0); toast.show(); }
Example 5
Source File: ToastUtils.java From ToastUtils with Apache License 2.0 | 5 votes |
/** * 设置当前Toast对象 */ public static void setToast(Toast toast) { checkNullPointer(toast); if (sToast != null && toast.getView() == null) { // 移花接木 toast.setView(sToast.getView()); toast.setGravity(sToast.getGravity(), sToast.getXOffset(), sToast.getYOffset()); toast.setMargin(sToast.getHorizontalMargin(), sToast.getVerticalMargin()); } sToast = toast; if (sStrategy != null) { sStrategy.bind(sToast); } }
Example 6
Source File: musicHandler.java From Android-Music-Player with MIT License | 5 votes |
public void playByPlaylistId(String str,int No){ int count = playlistHandler.getPlaylistLength(Ui.ef.getBaseContext().getContentResolver(),No); if(count == 0 || count == -1){ Toast toast = Toast.makeText(Gh.getBaseContext(), "Playlist is Empty.", Toast.LENGTH_SHORT); View view = toast.getView(); view.setBackgroundColor(0xFFD35D69); toast.show(); return; } resetDefault(); list = playlistHandler.getPlaylistByIds(Gh.getContentResolver(),Integer.parseInt(str)); if(list != null && list.size() != 0){ PID = -1; if(list != null && list.size() > 0){ AID = Integer.parseInt( list.get(0)[1]) ; } else { AID = -1; } } playlist.listName = playlistHandler.getPlaylistNameById(Gh.getContentResolver(),Integer.parseInt(str)); playlist.id = Integer.parseInt(str); playlist.save(list, playlist.listName); songPrepared = false; playByNumber(No); mEvent.trigger(playerEvents.PLAYLIST_CHANGED); }
Example 7
Source File: MedtronicCGMService.java From MedtronicUploader with GNU General Public License v2.0 | 5 votes |
/** * Launches a pop up message * @param message */ private void displayMessage(String message) { Toast toast = Toast.makeText(getBaseContext(), message, Toast.LENGTH_LONG); toast.setGravity(Gravity.CENTER, 0, 0); LinearLayout toastLayout = (LinearLayout) toast.getView(); TextView toastTV = (TextView) toastLayout.getChildAt(0); if (toastTV != null) { toastTV.setTextSize(20); toastTV.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL); } toast.show(); }
Example 8
Source File: Mixture.java From frenchtoast with Apache License 2.0 | 5 votes |
/** * Creates a {@link Mixture} from a {@link Toast}. Never call {@link Toast#show()} or {@link * Toast#cancel()} directly on that passed in {@link Toast}. */ public static Mixture dip(Toast toast) { if (toast.getView() == null) { throw new NullPointerException("Toast should have a view already set."); } return new Mixture(toast); }