当前位置: 首页>>代码示例>>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;未经允许,请勿转载。