當前位置: 首頁>>代碼示例>>Java>>正文


Java Toast.show方法代碼示例

本文整理匯總了Java中android.widget.Toast.show方法的典型用法代碼示例。如果您正苦於以下問題:Java Toast.show方法的具體用法?Java Toast.show怎麽用?Java Toast.show使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.widget.Toast的用法示例。


在下文中一共展示了Toast.show方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onLongClick

import android.widget.Toast; //導入方法依賴的package包/類
@Override
public boolean onLongClick(View v) {
  final int[] screenPos = new int[2];
  getLocationOnScreen(screenPos);

  final Context context = getContext();
  final int width = getWidth();
  final int height = getHeight();
  final int screenWidth = context.getResources().getDisplayMetrics().widthPixels;

  Toast cheatSheet = Toast.makeText(context, mTab.getContentDescription(),
									Toast.LENGTH_SHORT);
  // Show under the tab
  cheatSheet.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL,
						(screenPos[0] + width / 2) - screenWidth / 2, height);

  cheatSheet.show();
  return true;
}
 
開發者ID:TIIEHenry,項目名稱:TIIEHenry-Android-SDK,代碼行數:20,代碼來源:TabLayout.java

示例2: show

import android.widget.Toast; //導入方法依賴的package包/類
public void show() {
    final Toast toast = new Toast(context);
    final View toastLayout = ((LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE))
            .inflate(R.layout.poizi_toast_layout, null);

    ImageView imgToastIcon = (ImageView) toastLayout.findViewById(R.id.imgToastIcon);
    TextView tvToastText = (TextView) toastLayout.findViewById(R.id.tvToastText);
    LinearLayout llPoiziToastRoot = (LinearLayout) toastLayout.findViewById(R.id.llPoiziToastRoot);

    initLlPoiziToastRoot(llPoiziToastRoot);
    initToastText(tvToastText);
    initToastIcon(imgToastIcon);

    toast.setView(toastLayout);

    toast.setDuration(poiziToastOptionModel.getDuration());

    setGravity(toast);

    toast.show();
}
 
開發者ID:Poizi,項目名稱:PoiziToast,代碼行數:22,代碼來源:Exhibitioner.java

示例3: insertNameinDB

import android.widget.Toast; //導入方法依賴的package包/類
private void insertNameinDB() throws UnsupportedEncodingException {
    if (name.equals("")) {
        Context context = getActivity().getApplicationContext();
        CharSequence text = "Hei, nu ai niciun nume!";
        int duration = Toast.LENGTH_SHORT;
        Toast toast = Toast.makeText(context, text, duration);
        toast.show();
    } else {

        //inserare in baza de data a numelui si scorului
        Log.e("INSERT:", name + " " + score);
        new UserInsert().execute();
        Intent newActivityRanking = new Intent(getActivity(), RankingActivity.class);
        startActivity(newActivityRanking);
        getActivity().finish();

    }
}
 
開發者ID:cristian-cojocaru,項目名稱:QuizApp-Android,代碼行數:19,代碼來源:FragScore.java

示例4: checkconnection

import android.widget.Toast; //導入方法依賴的package包/類
public void checkconnection()
{
    ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    android.net.NetworkInfo wifi = cm
            .getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    android.net.NetworkInfo datac = cm
            .getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
    if ((wifi != null & datac != null)
            && (wifi.isConnected() | datac.isConnected())) {
        //connection is avlilable
    }else{
        //no connection
        Toast toast = Toast.makeText(MainActivity.this, "No Internet Connection Please make Internet for Contine",
                Toast.LENGTH_SHORT);
        toast.show();
    }
}
 
開發者ID:Shobhit-pandey,項目名稱:CollegeDoc,代碼行數:18,代碼來源:MainActivity.java

示例5: onCreate

import android.widget.Toast; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    AssetManager assetManager = getAssets();
    try {
        InputStream inputStream = assetManager.open("words.txt");
        BufferedReader in = new BufferedReader(new InputStreamReader(inputStream));
        String line = null;
        while((line = in.readLine()) != null) {
            String word = line.trim();
            /**
             **
             **  YOUR CODE GOES HERE
             **
             **/
        }
    } catch (IOException e) {
        Toast toast = Toast.makeText(this, "Could not load dictionary", Toast.LENGTH_LONG);
        toast.show();
    }
    LinearLayout verticalLayout = (LinearLayout) findViewById(R.id.vertical_layout);
    stackedLayout = new StackedLayout(this);
    verticalLayout.addView(stackedLayout, 3);

    View word1LinearLayout = findViewById(R.id.word1);
    word1LinearLayout.setOnTouchListener(new TouchListener());
    //word1LinearLayout.setOnDragListener(new DragListener());
    View word2LinearLayout = findViewById(R.id.word2);
    word2LinearLayout.setOnTouchListener(new TouchListener());
    //word2LinearLayout.setOnDragListener(new DragListener());
}
 
開發者ID:bricam,項目名稱:wordstack,代碼行數:33,代碼來源:MainActivity.java

示例6: warnIfNoExternalStorage

import android.widget.Toast; //導入方法依賴的package包/類
private void warnIfNoExternalStorage()
   {
String storageState = Environment.getExternalStorageState();
if (!storageState.equals(Environment.MEDIA_MOUNTED))
{
    //  myLog.i("Warning due to storage state " + storageState);
    Toast toast = Toast.makeText(mActivity, R.string.storage_warning, Toast.LENGTH_LONG);
    toast.setGravity(Gravity.CENTER, 0, 0);
    toast.show();
}
   }
 
開發者ID:stytooldex,項目名稱:stynico,代碼行數:12,代碼來源:ServerControlActivity.java

示例7: showWhiteSnackBar

import android.widget.Toast; //導入方法依賴的package包/類
public static void showWhiteSnackBar(int signed_in_message, AppCompatActivity compatActivity) {
    LayoutInflater inflater = compatActivity.getLayoutInflater();
    View layout = inflater.inflate(R.layout.custom_toast_view,
            (ViewGroup) compatActivity.findViewById(R.id.custom_toast_container));
    TextView text = (TextView) layout.findViewById(R.id.text);
    text.setText(signed_in_message);
    Toast toast = new Toast(compatActivity);
    toast.setDuration(Toast.LENGTH_SHORT);
    toast.setView(layout);
    toast.show();
}
 
開發者ID:vixir,項目名稱:Perfect-Day,代碼行數:12,代碼來源:Utils.java

示例8: onBackPressed

import android.widget.Toast; //導入方法依賴的package包/類
@Override
public void onBackPressed() {
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    if (drawer.isDrawerOpen(GravityCompat.START)) {
        drawer.closeDrawer(GravityCompat.START);
    } else if (1 == mViewPager.getCurrentItem()) {
        mViewPager.setCurrentItem(0);
    } else {
        if (doubleBackToExitPressedOnce) {
            super.onBackPressed();
            return;
        }

        this.doubleBackToExitPressedOnce = true;
        Toast makeText = Toast.makeText(this, "再按一次退出", Toast.LENGTH_SHORT);
        makeText.setDuration(Toast.LENGTH_SHORT);
        makeText.show();

        new Handler().postDelayed(new Runnable() {

            @Override
            public void run() {
                doubleBackToExitPressedOnce = false;
            }
        }, 2000);
    }
}
 
開發者ID:Sayi,項目名稱:RestClient,代碼行數:28,代碼來源:HomeActivity.java

示例9: showCustomToast

import android.widget.Toast; //導入方法依賴的package包/類
/** 顯示自定義Toast提示(來自String) **/
protected void showCustomToast(String text) {
	View toastRoot = LayoutInflater.from(BaseActivity.this).inflate(
			R.layout.common_toast, null);
	((HandyTextView) toastRoot.findViewById(R.id.toast_text)).setText(text);
	Toast toast = new Toast(BaseActivity.this);
	toast.setGravity(Gravity.CENTER, 0, 0);
	toast.setDuration(Toast.LENGTH_SHORT);
	toast.setView(toastRoot);
	toast.show();
}
 
開發者ID:qizhenghao,項目名稱:HiBangClient,代碼行數:12,代碼來源:BaseActivity.java

示例10: popAlarmSetToast

import android.widget.Toast; //導入方法依賴的package包/類
/**
 * Display a toast that tells the user how long until the alarm
 * goes off.  This helps prevent "am/pm" mistakes.
 */
static void popAlarmSetToast(Context context, long timeInMillis) {
  String toastText = formatToast(context, timeInMillis);
  Toast toast = Toast.makeText(context, toastText, Toast.LENGTH_LONG);
  ToastMaster.setToast(toast);
  toast.show();
}
 
開發者ID:nordfalk,項目名稱:EsperantoRadio,代碼行數:11,代碼來源:SetAlarm_akt.java

示例11: showErrorToast

import android.widget.Toast; //導入方法依賴的package包/類
/**
 * 顯示錯誤的Toast
 *
 * @param text String
 */
public static void showErrorToast(Context context, String text) {
    View view = View.inflate(context, R.layout.toast_view_prompt, null);
    TextView tv = (TextView) view.findViewById(R.id.tv_toast_prompt);
    tv.setText(text);
    tv.setCompoundDrawablesWithIntrinsicBounds(R.drawable.toast_show_error, 0, 0, 0);

    Toast toast = getToast(context, view);
    toast.show();
}
 
開發者ID:wzx54321,項目名稱:XinFramework,代碼行數:15,代碼來源:ToastPrompt.java

示例12: onPreferenceChange

import android.widget.Toast; //導入方法依賴的package包/類
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
    // In this context, we're using the onPreferenceChange listener for checking whether the
    // radius setting was set to a valid value.

    //the error message that will be shown if an invalid value is entered
    Toast error = Toast.makeText(getContext(), "Please select a number greater than 0", Toast.LENGTH_SHORT);

    // Double check that the preference is the radius preference
    String sizeKey = getString(R.string.pref_radius_key);
    if (preference.getKey().equals(sizeKey)) {
        String radius = (String) newValue;
        try {
            double size = Double.parseDouble(radius);
            // If the number is outside of the acceptable range, show an error.
            if (size <= 0) {
                error.show();
                return false;
            }
        } catch (NumberFormatException nfe) {
            // If whatever the user entered can't be parsed to a number, show an error
            error.show();
            return false;
        }
    }

    //numbers seems to be valid; accept it
    return true;
}
 
開發者ID:Jugendhackt,項目名稱:Camera-warner,代碼行數:30,代碼來源:SettingsFragment.java

示例13: showToastSavor

import android.widget.Toast; //導入方法依賴的package包/類
/**
 * 與app色調一致的自定義Toast
 * @param context
 * @param msg 要展示的信息
 */
public static void showToastSavor(Context context, String msg) {
    LayoutInflater layoutInflater = LayoutInflater.from(context);
    View inflate = layoutInflater.inflate(R.layout.view_text, null);
    ((TextView) inflate.findViewById(R.id.custom_toast)).setText(msg);
    Toast toast = new Toast(context);
    toast.setGravity(Gravity.CENTER, 0, 0);
    toast.setView(inflate);
    toast.setDuration(Toast.LENGTH_SHORT);
    toast.show();
}
 
開發者ID:SavorGit,項目名稱:Hotspot-master-devp,代碼行數:16,代碼來源:ToastUtil.java

示例14: customDisplay

import android.widget.Toast; //導入方法依賴的package包/類
private void customDisplay(String msg) {
    Toast tt = new Toast(this);
    LayoutInflater inflator = this.getLayoutInflater();
    View vv = inflator.inflate(R.layout.custom_toast_layout, null);
    TextView cTv = (TextView) vv.findViewById(R.id.cTv);
    cTv.setText(msg);
    vv.requestLayout();
    tt.setView(vv);
    tt.setGravity(Gravity.CENTER, 0, 0);
    tt.show();
}
 
開發者ID:shivam301296,項目名稱:2048-TimeKiller,代碼行數:12,代碼來源:Game.java

示例15: show

import android.widget.Toast; //導入方法依賴的package包/類
/**
 * 顯示吐司
 *
 * @param text     文本
 * @param duration 顯示時長
 */
private static void show(CharSequence text, int duration) {
    cancel();
    if (customView != null) {
        sToast = new Toast(App.app);
        sToast.setView(customView);
        sToast.setDuration(duration);
    } else {
        sToast = Toast.makeText(App.app, text, duration);
    }
    sToast.setGravity(gravity, xOffset, yOffset);
    sToast.show();
}
 
開發者ID:Lingzh0ng,項目名稱:BrotherWeather,代碼行數:19,代碼來源:ToastUtils.java


注:本文中的android.widget.Toast.show方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。