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


Java Toast.makeText方法代碼示例

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


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

示例1: show

import android.widget.Toast; //導入方法依賴的package包/類
/**
 * Show a toast.
 *
 * @param text         The text to show.
 * @param durationLong Whether the toast show for a long period of time?
 * @param mode         The display mode to use.  Either {@link Mode#NORMAL} or {@link Mode#REPLACEABLE}
 */
public static void show(CharSequence text, boolean durationLong, Mode mode) {
    final int duration = durationLong ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT;

    if (mode != Mode.REPLACEABLE) {
        Toast.makeText(sContext, text, duration).show();
        return;
    }

    if (sToast == null || sDuration != duration) {
        sDuration = duration;
        sToast = Toast.makeText(sContext, text, duration);
    } else {
        try {
            sToast.setText(text);
        } catch (RuntimeException e) {
            sToast = Toast.makeText(sContext, text, duration);
        }
    }
    sToast.show();
}
 
開發者ID:GuJin,項目名稱:ToastUtil,代碼行數:28,代碼來源:ToastUtil.java

示例2: show

import android.widget.Toast; //導入方法依賴的package包/類
public static void show(Context context, String msg, boolean isLong, int gravity) {
    if (context == null || msg == null) {
        return;
    }

    if (toast == null) { // Create Toast firstly.
        toast = Toast.makeText(context.getApplicationContext(), msg,
                isLong ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT);
        defGravity = toast.getGravity();
        offsetX = toast.getXOffset();
        offsetY = toast.getYOffset();
    } else {
        toast.setDuration(isLong ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT);
        toast.setText(msg);
    }

    if (gravity == -1) {
        toast.setGravity(defGravity, offsetX, offsetY);
    } else {
        toast.setGravity(gravity, 0, 0);
    }

    toast.show();
}
 
開發者ID:by-syk,項目名稱:GlobalToast,代碼行數:25,代碼來源:GlobalToast.java

示例3: showLongCustomToast

import android.widget.Toast; //導入方法依賴的package包/類
@SuppressLint("ShowToast")
public static void showLongCustomToast(final Context context, final String text) {

    if (Looper.myLooper() == Looper.getMainLooper()) {
        if (toast == null) {
            toast = Toast.makeText(context.getApplicationContext(), text, Toast.LENGTH_LONG);
        }
        toast.setText(text);
        toast.show();
    } else {
        HandlerUtils.getHandler().post(new Runnable() {
            @Override
            public void run() {
                if (toast == null) {
                    toast = Toast.makeText(context.getApplicationContext(), text, Toast.LENGTH_LONG);
                }
                toast.setText(text);
                toast.show();
            }
        });
    }
}
 
開發者ID:StickyTolt,項目名稱:ForeverLibrary,代碼行數:23,代碼來源:ToastUtils.java

示例4: onClick

import android.widget.Toast; //導入方法依賴的package包/類
@Override
public void onClick(View v) {
    //switch (v.getId()) {
    if (v.getId() == GoogleSignInButton){
        //case GoogleSignInButton: {
        if(isNetworkAvailable(this)) {
            signIn();
        } else {
            Toast toast = Toast.makeText(getApplicationContext(),
                    getResources().getString(R.string.network_unavailable_toast), Toast.LENGTH_SHORT);
            toast.show();
        }
            //break;
        //}
    }
    else if (v.getId() == SkipSignInButton) {
        Intent intent = new Intent(SignInActivity.this, MainActivity.class);
        startActivity(intent);
    }
}
 
開發者ID:AviralGarg1993,項目名稱:VR-One,代碼行數:21,代碼來源:SignInActivity.java

示例5: 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

示例6: show

import android.widget.Toast; //導入方法依賴的package包/類
public static void show(String text) {
    if (toast == null) {
        toast = Toast.makeText(MyApplication.getInstance(), "", Toast.LENGTH_SHORT);
        toast.setGravity(Gravity.CENTER, 0, 0);
    }
    toast.setText(text);
    toast.show();
}
 
開發者ID:sundevin,項目名稱:rxjava2_retrofit2,代碼行數:9,代碼來源:ToastUtils.java

示例7: showToast

import android.widget.Toast; //導入方法依賴的package包/類
/**
 * 顯示吐司
 *
 * @param text     文本
 * @param duration 顯示時長
 */
private static void showToast(CharSequence text, int duration) {
    if (isJumpWhenMore) cancelToast();
    if (sToast == null) {
        sToast = Toast.makeText(Utils.getContext(), text, duration);
    } else {
        sToast.setText(text);
        sToast.setDuration(duration);
    }
    sToast.show();
}
 
開發者ID:angcyo,項目名稱:RLibrary,代碼行數:17,代碼來源:ToastUtils.java

示例8: single

import android.widget.Toast; //導入方法依賴的package包/類
/**
 * 彈出多個toast時, 不會一個一個的彈, 後麵一個要顯示的內容直接顯示在當前的toast上
 */
public static void single(Context context,String msg) {
    if (toast == null) {
        toast = Toast.makeText(context, msg, Toast.LENGTH_SHORT);
    } else {
        toast.setText(msg);
    }
    toast.show();
}
 
開發者ID:supremezzz,項目名稱:Supreme,代碼行數:12,代碼來源:ToastUtil.java

示例9: showToast

import android.widget.Toast; //導入方法依賴的package包/類
private void showToast(String p_strMessage) {
    if (m_jToast == null) {
        m_jToast = Toast.makeText(m_jContext, "", Toast.LENGTH_SHORT);
    }

    m_jToast.setText(p_strMessage);
    m_jToast.show();
}
 
開發者ID:evrencoskun,項目名稱:TableView,代碼行數:9,代碼來源:TableViewListener.java

示例10: setToastPosition

import android.widget.Toast; //導入方法依賴的package包/類
public static Toast setToastPosition(Context context, String string ,int grivity,int xOffset, int yOffset){
	if (context == null)
		return null;
	if(toast == null){
		toast = Toast.makeText(context,string,Toast.LENGTH_SHORT);
	}else{
		toast.setText(string);
	}
	toast.setGravity(grivity,xOffset, yOffset);
	return toast;
}
 
開發者ID:androidstarjack,項目名稱:ServiceDownLoadApp-master,代碼行數:12,代碼來源:GetToast.java

示例11: showToast

import android.widget.Toast; //導入方法依賴的package包/類
public void showToast(CharSequence msg) {
    Activity activity = getActivity();
    if (activity != null) {
        if (toast == null) toast = Toast.makeText(activity, msg, Toast.LENGTH_SHORT);
        toast.setText(msg);
        toast.show();
    }
}
 
開發者ID:guzhigang001,項目名稱:QNewsDemo,代碼行數:9,代碼來源:ActivityUtils.java

示例12: showPasteMessage

import android.widget.Toast; //導入方法依賴的package包/類
@SuppressLint("NewApi")
private void showPasteMessage(String label) {
  if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
    return;
  }
  final Toast toast = Toast.makeText(webView.getContext(), label, Toast.LENGTH_LONG);
  toast.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL, 0, 0);
  toast.show();
}
 
開發者ID:disit,項目名稱:siiMobilityAppKit,代碼行數:10,代碼來源:SocialSharing.java

示例13: showToast

import android.widget.Toast; //導入方法依賴的package包/類
private void showToast(int resid) {
    if (mToast == null) {
        mToast = Toast.makeText(this, "", Toast.LENGTH_SHORT);
    }
    mToast.setText(resid);
    mToast.show();
}
 
開發者ID:89luca89,項目名稱:ThunderMusic,代碼行數:8,代碼來源:MediaPlaybackCarModeActivity.java

示例14: showToast

import android.widget.Toast; //導入方法依賴的package包/類
public void showToast(int resId) {
    String text = getResources().getString(resId);
    if (mToast == null) {
        mToast = Toast.makeText(MessageActivity.this, text, Toast.LENGTH_SHORT);
    } else {
        mToast.setText(text);
        mToast.setDuration(Toast.LENGTH_SHORT);
    }
    mToast.setGravity(Gravity.CENTER, 0, 0);
    mToast.show();
}
 
開發者ID:ccfish86,項目名稱:sctalk,代碼行數:12,代碼來源:MessageActivity.java

示例15: displayShortToast

import android.widget.Toast; //導入方法依賴的package包/類
public void displayShortToast(Context context,String msg){
    if(context == null){
        return;
    }
    if(mToast == null){
        mToast = Toast.makeText(context, msg, Toast.LENGTH_SHORT);
    }
    mToast.setText(msg);
    mToast.show();
}
 
開發者ID:Sugarya,項目名稱:Closet,代碼行數:11,代碼來源:HintUtils.java


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