本文整理汇总了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();
}
示例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();
}
示例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();
}
});
}
}
示例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);
}
}
示例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();
}
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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;
}
示例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();
}
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}