List of usage examples for android.widget Toast Toast
public Toast(Context context)
From source file:MainActivity.java
public void showToast(View view) { LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View layout = inflater.inflate(R.layout.toast_custom, null); ((TextView) layout.findViewById(android.R.id.message)).setText("Custom Toast"); Toast toast = new Toast(this); toast.setGravity(Gravity.CENTER, 0, 0); toast.setDuration(Toast.LENGTH_LONG); toast.setView(layout);/*from ww w . ja v a2 s . c o m*/ toast.show(); }
From source file:com.endiansoftware.echo.remotewatch.GcmBroadcastReceiver.java
@Override public void onReceive(Context context, Intent intent) { /*/*from w w w. j av a 2 s . co m*/ // Explicitly specify that GcmIntentService will handle the intent. ComponentName comp = new ComponentName(context.getPackageName(), GcmIntentService.class.getName()); // Start the service, keeping the device awake while it is launching. startWakefulService(context, (intent.setComponent(comp))); setResultCode(Activity.RESULT_OK); */ /* // ? ?? . Intent popupIntent = new Intent(context, Popup.class) .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); // . context.startActivity(popupIntent); */ LinearLayout layout = new LinearLayout(context); //layout.setBackgroundResource(R.color.LightOrange); TextView tv = new TextView(context); // set the TextView properties like color, size etc tv.setTextColor(Color.RED); tv.setTextSize(15); tv.setGravity(Gravity.CENTER_VERTICAL); // set the text you want to show in Toast tv.setText("My Custom Toast at Bottom of Screen"); layout.addView(tv); Toast toast = new Toast(context); //context is object of Context write "this" if you are an Activity // Set The layout as Toast View toast.setView(layout); // Position you toast here toast position is 50 dp from bottom you can give any integral value toast.setGravity(Gravity.BOTTOM, 0, 50); toast.show(); }
From source file:com.andrewshu.android.reddit.common.Common.java
public static void showErrorToast(String error, int duration, Context context) { LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); Toast t = new Toast(context); t.setDuration(duration);//from www . ja v a2 s . c o m View v = inflater.inflate(R.layout.error_toast, null); TextView errorMessage = (TextView) v.findViewById(R.id.errorMessage); errorMessage.setText(error); t.setView(v); t.show(); }
From source file:com.accia77.mockey.ui.PapiroActivity.java
@Override public void onResume() { super.onResume(); setTitle(MyApplication.getInstance().getMainActivityTitle()); massimaSceltaTextView = (TextView) findViewById(R.id.massimaSceltaTextView); String stringaTextView = currentEntry.getUserEditedEntry(); if (mDoShowAndPlayQuote) { // Custom toast con il testo della frase LayoutInflater inflater = getLayoutInflater(); View layout = inflater.inflate(R.layout.papiro_toast, (ViewGroup) findViewById(R.id.toast_layout_root)); ImageView image = (ImageView) layout.findViewById(R.id.papiro_toast_image); image.setImageResource(R.drawable.ic_small_monkey_head); TextView text = (TextView) layout.findViewById(R.id.papiro_toast_text); text.setText(stringaTextView);// w ww. ja va 2s .co m Toast toast = new Toast(this); toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0); toast.setDuration(Toast.LENGTH_SHORT); toast.setView(layout); toast.show(); // Playback of the quote if (currentEntry.getEntryType() == MySQLiteHelper.ENTRY_TYPE_PURE_TEXT) { MyApplication.getInstance().playSelection(currentEntry); } else if (currentEntry.getEntryType() == MySQLiteHelper.ENTRY_TYPE_AUDIO) { // No playback if the sd card is not mounted if (MyApplication.getInstance().isSdCardMounted(false)) { MyApplication.getInstance().playSelection(currentEntry); } } mDoShowAndPlayQuote = false; } if (MyApplication.getInstance().isDefaultPapiroLoaded()) { massimaSceltaTextView.setText(stringaTextView); massimaSceltaTextView.setVisibility(View.VISIBLE); } else massimaSceltaTextView.setVisibility(View.INVISIBLE); }
From source file:org.xingjitong.ui.CallButton.java
private void toastdsp(String str) { //LayoutInflater inflater = getLayoutInflater(); LayoutInflater inflater = LayoutInflater.from(getContext()); View layout = inflater.inflate(R.layout.customtoast, (ViewGroup) findViewById(R.id.llcustomtoast)); //ImageView image = (ImageView) layout.findViewById(R.id.customtoast_img); //image.setImageResource(R.drawable.status_green); //yypp TextView text = (TextView) layout.findViewById(R.id.customtoast_text); text.setText(str);/* w w w . jav a 2s .co m*/ //Toast toast = new Toast(getApplicationContext()); Toast toast = new Toast(getContext()); toast.setGravity(Gravity.CENTER, 0, 60); //toast.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL, 0, 0); toast.setDuration(Toast.LENGTH_LONG); toast.setView(layout); toast.show(); }
From source file:com.zephyrteam.costituzione.DetailedActivity.java
@SuppressWarnings("static-access") public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.copy_entry: String toCopy = mEntry.getTitle() + ": \n" + mEntry.getBody().replace("\n\n", "\n"); ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setPrimaryClip(ClipData.newPlainText("Costituzione", toCopy)); new Toast(this).makeText(this, R.string.text_copied_to_clipboard, 2000).show(); break;/*from w w w. jav a2s . c om*/ case R.id.favourite_status: DatabaseHandler dbh = new DatabaseHandler(this); dbh.open(true); mEntry.setIsFavourite(!mEntry.isFavourite()); dbh.updateFavoriteStatus(mEntry); dbh.close(); new Toast(this) .makeText(this, mEntry.isFavourite() ? R.string.added_to_fav : R.string.removed_from_fav, 2000) .show(); updateFavoriteButton(item); } return true; }
From source file:de.baumann.hhsmoodle.helper.helper_main.java
public static void makeToast(Activity activity, String Text) { LayoutInflater inflater = activity.getLayoutInflater(); View toastLayout = inflater.inflate(R.layout.toast, (ViewGroup) activity.findViewById(R.id.toast_root_view)); TextView header = (TextView) toastLayout.findViewById(R.id.toast_message); header.setText(Text);//from w w w . j a va 2 s. co m Toast toast = new Toast(activity.getApplicationContext()); toast.setGravity(Gravity.FILL_HORIZONTAL | Gravity.BOTTOM, 0, 0); toast.setDuration(Toast.LENGTH_LONG); toast.setView(toastLayout); toast.show(); }
From source file:com.breadwallet.BreadWalletApp.java
/** * Shows a custom toast using the given string as a paramater, * * @param message the message to be shown in the custom toast *//* www . j a va2 s . com*/ public void showCustomToast(Activity app, String message, int yOffSet, int duration, int color) { if (toast == null) toast = new Toast(getApplicationContext()); if (MainActivity.appInBackground) return; if (customToastAvailable || !oldMessage.equals(message)) { oldMessage = message; customToastAvailable = false; new Handler().postDelayed(new Runnable() { @Override public void run() { customToastAvailable = true; } }, 1000); LayoutInflater inflater = app.getLayoutInflater(); View layout = inflater.inflate(R.layout.toast, (ViewGroup) app.findViewById(R.id.toast_layout_root)); if (color == 1) { layout.setBackgroundResource(R.drawable.toast_layout_black); } TextView text = (TextView) layout.findViewById(R.id.toast_text); text.setText(message); toast.setGravity(Gravity.BOTTOM, 0, yOffSet); toast.setDuration(duration); toast.setView(layout); toast.show(); } }
From source file:com.neu.fragment.BancheTimeFragment.java
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.banche_info, null); screenWidth = getActivity().getWindowManager().getDefaultDisplay().getWidth(); screenHeight = getActivity().getWindowManager().getDefaultDisplay().getHeight(); toast = new Toast(getActivity()); // System.out.println(screenHeight+"px"); // System.out.println("width:" + screenWidth); tableInfo = (TableLayout) view.findViewById(R.id.tableInfo); fromHunnan = (RelativeLayout) view.findViewById(R.id.hunnan_bt); fromNanhu = (RelativeLayout) view.findViewById(R.id.nanhu_bt); from_tx = (TextView) view.findViewById(R.id.from_tx); // spinner = (Spinner) view.findViewById(R.id.spinner_type); // ???/*from w ww . j av a 2s . c o m*/ selected_image = (ImageView) view.findViewById(R.id.selected_image); selected_name = (TextView) view.findViewById(R.id.selected_name); searchName = selected_name.getText().toString(); searchName_fore = searchName; stu_show = (LinearLayout) view.findViewById(R.id.stu_show); dialog = MyDialog.createLoadingDialog(getActivity(), "..."); freshInfo = (TextView) view.findViewById(R.id.fresh_info); //?? freshInfo.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { new Thread(new Runnable() { String result = ""; @Override public void run() { try { // TODO Auto-generated method stub //xml??? StoreBancheInfoUtils.storeInfoFromNet(getActivity()); } catch (UnkownNetWorkException e) { System.out.println(e.getMessage()); Message msg = new Message(); msg.what = MSG_NETERROR; handler.sendMessage(msg); } catch (IOException e) { // TODO: handle exception } } }).start(); } }); // popMenu final PopMenu popMenu = new PopMenu(getActivity(), screenWidth); // ?? RelativeLayout showType = (RelativeLayout) view.findViewById(R.id.select_type); showType.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { // TODO Auto-generated method stub popMenu.showAsDropDown(view); } }); // ? popMenu.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // TODO Auto-generated method stub searchName = ((Person) parent.getItemAtPosition(position)).getItem_name().toString(); int drawable = ((Person) parent.getItemAtPosition(position)).getItem_image(); selected_image.setBackgroundResource(drawable); selected_name.setText(searchName); if (searchName.equals("")) { if (!searchName_fore.equals(searchName)) { stu_show.setVisibility(View.VISIBLE); from_tx.setText(""); tableInfo.removeAllViews(); } } else if (searchName.equals("?")) { if (!searchName_fore.equals(searchName)) { stu_show.setVisibility(View.GONE); from_tx.setText(""); tableInfo.removeAllViews(); } } searchName_fore = searchName; popMenu.dismiss(); } }); fromHunnan.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { from = "?"; task = new SearchAsyncTask(); task.dialog = dialog; task.from = from; task.stu_show = stu_show; task.from_tx = from_tx; task.toast = toast; task.searchName = searchName; task.tableInfo = tableInfo; task.execute(); } }); fromNanhu.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { if (searchName.equals("")) from = "??"; else from = "?"; task = new SearchAsyncTask(); task.dialog = dialog; task.from = from; task.toast = toast; task.stu_show = stu_show; task.from_tx = from_tx; task.searchName = searchName; task.tableInfo = tableInfo; task.execute(); } }); return view; }
From source file:com.concentricsky.android.khanacademy.data.remote.KAAPIAdapter.java
/** * Call me from the UI thread, please.//from w w w. j av a2 s. c o m * * Meant for use by broadcast receivers receiving ACTION_BADGE_EARNED. * */ public void toastBadge(Badge badge) { BadgeCategory category = badge.getCategory(); // Dao<BadgeCategory, Integer> dao = dataService.getHelper().getDao(BadgeCategory.class); // dao.refresh(category); Toast toast = new Toast(dataService); View content = LayoutInflater.from(dataService).inflate(R.layout.badge, null, false); ImageView iconView = (ImageView) content.findViewById(R.id.badge_image); TextView pointsView = (TextView) content.findViewById(R.id.badge_points); TextView titleView = (TextView) content.findViewById(R.id.badge_title); TextView descView = (TextView) content.findViewById(R.id.badge_description); iconView.setImageResource(category.getIconResourceId()); int points = badge.getPoints(); if (points > 0) { pointsView.setText(points + ""); } else { pointsView.setVisibility(View.GONE); } titleView.setText(badge.getDescription()); descView.setText(badge.getSafe_extended_description()); toast.setView(content); toast.setDuration(Toast.LENGTH_LONG); toast.setGravity(Gravity.TOP, 0, 200); toast.show(); }