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


Java Toast.LENGTH_LONG屬性代碼示例

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


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

示例1: showToast

/**
 * {@link #tintDrawable(Drawable, ColorStateList)}
 * @param content content to show
 * @param longTime short or long
 * @param context context
 * @param textColor toast text color
 * @param toastBackgroundColor toast background color
 */
public static void showToast(@NonNull Context context, String content, boolean longTime,@ColorInt int toastBackgroundColor ,@ColorInt
        int textColor) {
    int type = longTime ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT;
    Toast toast = Toast.makeText(context, content, type);
    View toastView = toast.getView();
    TextView textView = (TextView) toastView.findViewById(android.R.id.message);
    if (toastBackgroundColor != 0){
        Drawable toastBackgroundDrawable = tintDrawable(toastView.getBackground(), ColorStateList.valueOf(toastBackgroundColor));
        toastView.setBackgroundDrawable(toastBackgroundDrawable);
    }
    if (textColor!=0){
        textView.setTextColor(textColor);
    }
    toast.setView(toastView);
    toast.setText(content);
    toast.show();
}
 
開發者ID:didikee,項目名稱:CommonDependence,代碼行數:25,代碼來源:UIToast.java

示例2: showToast

/**
 * {@link layout/transient_notification.xml}
 * @param content content to show
 * @param longTime short or long
 * @param context context
 * @param textColor toast text color
 * @param toastBackgroundColor toast background color
 */
public static void showToast(@NonNull Context context, String content, boolean longTime, @ColorInt
        int textColor,@ColorInt int toastBackgroundColor) {
    int type = longTime ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT;
    Toast toast = Toast.makeText(context, content, type);
    ViewGroup toastView = (ViewGroup) LayoutInflater.from(context).inflate(R.layout
            .layout_toast, null, false);
    if (toastBackgroundColor != 0) {
        toastView.setBackgroundDrawable(getToastBackground(context, toastBackgroundColor));
    }
    TextView textView = (TextView) toastView.findViewById(android.R.id.message);
    // 內部已經作非空判斷了
    if (textColor!=0){
        textView.setTextColor(textColor);
    }
    Typeface typeface = Typeface.create("sans-serif-condensed", Typeface.NORMAL);
    textView.setTypeface(typeface);
    toast.setView(toastView);
    toast.setText(content);
    toast.show();
}
 
開發者ID:didikee,項目名稱:CommonDependence,代碼行數:28,代碼來源:UIToast2.java

示例3: getStorageDir

public File getStorageDir(Context context, String directoryName) {
    File file =
            new File(Environment.getExternalStoragePublicDirectory("/"), directoryName);

    System.out.println("canRead " + Environment.getExternalStorageDirectory().canRead());
    System.out.println("canWrite " + Environment.getExternalStorageDirectory().canWrite());

    boolean ok = file.mkdirs(); //create folders where write files
    if (!ok) {
        CharSequence text = "Failed to create dir " + file;
        int duration = Toast.LENGTH_LONG;

        Toast toast = Toast.makeText(context, text, duration);
        toast.show();
    }
    return file;
}
 
開發者ID:JumpMind,項目名稱:symmetric-android-client-demo,代碼行數:17,代碼來源:MainActivity.java

示例4: show

/**
 * 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,代碼行數:27,代碼來源:ToastUtil.java

示例5: run

public void run()
{
	String s = aFile.getName();
	setTitleBarText(aFile.getName());


	progressDlg.dismiss();
	int duration = Toast.LENGTH_LONG;
	Toast.makeText(TextEdit.this, getString(R.string.toast_save) + ": " + s, duration).show();


	setResultForActionGetContent();

	if(closeAfterSaveFlag)
	{
		finish();
	}

	messageDigest = getMessageDigest();
}
 
開發者ID:monolifed,項目名稱:mininoteview,代碼行數:20,代碼來源:TextEdit.java

示例6: showToast

/**
 * show a toast using resource Globals.getId()
 *
 * @param context
 * @param resId
 * @param isLong
 */
public static void showToast(final Context context, final int resId, final boolean isLong) {
    if (isLong) {
        LENGTH = Toast.LENGTH_LONG;
    } else {
        LENGTH = Toast.LENGTH_SHORT;
    }
    showToast(context, context.getString(resId));
}
 
開發者ID:alibaba,項目名稱:LuaViewPlayground,代碼行數:15,代碼來源:ToastUtil.java

示例7: toast

@WXModuleAnno
public void toast(String param) {

  String message = "";
  int duration = Toast.LENGTH_SHORT;
  if (!TextUtils.isEmpty(param)) {
    try {
      param = URLDecoder.decode(param, "utf-8");
      JSONObject jsObj = new JSONObject(param);
      message = jsObj.optString(MESSAGE);
      duration = jsObj.optInt(DURATION);
    } catch (Exception e) {
      WXLogUtils.e("[WXModalUIModule] alert param parse error ", e);
    }
  }
  if (TextUtils.isEmpty(message)) {
    WXLogUtils.e("[WXModalUIModule] toast param parse is null ");
    return;
  }

  if (duration > 3) {
    duration = Toast.LENGTH_LONG;
  } else {
    duration = Toast.LENGTH_SHORT;
  }
  if(toast== null){
    toast =Toast.makeText(mWXSDKInstance.getContext(), message, duration);
  } else {
    toast.setDuration(duration);
    toast.setText(message);
  }
  toast.setGravity(Gravity.CENTER, 0, 0);
  toast.show();
}
 
開發者ID:amap-demo,項目名稱:weex-3d-map,代碼行數:34,代碼來源:WXModalUIModule.java

示例8: toast

@JSMethod(uiThread = true)
public void toast(String param) {

  String message = "";
  int duration = Toast.LENGTH_SHORT;
  if (!TextUtils.isEmpty(param)) {
    try {
      param = URLDecoder.decode(param, "utf-8");
      JSONObject jsObj = JSON.parseObject(param);
      message = jsObj.getString(MESSAGE);
      duration = jsObj.getInteger(DURATION);
    } catch (Exception e) {
      WXLogUtils.e("[WXModalUIModule] alert param parse error ", e);
    }
  }
  if (TextUtils.isEmpty(message)) {
    WXLogUtils.e("[WXModalUIModule] toast param parse is null ");
    return;
  }

  if (duration > 3) {
    duration = Toast.LENGTH_LONG;
  } else {
    duration = Toast.LENGTH_SHORT;
  }
  if (toast == null) {
    toast = Toast.makeText(mWXSDKInstance.getContext(), message, duration);
  } else {
    toast.setDuration(duration);
    toast.setText(message);
  }
  toast.setGravity(Gravity.CENTER, 0, 0);
  toast.show();
}
 
開發者ID:weexext,項目名稱:ucar-weex-core,代碼行數:34,代碼來源:WXModalUIModule.java

示例9: notifyIfNotGranted

/**
 * Checks for permissions and notifies the user if they aren't granted
 **/
public static void notifyIfNotGranted(@NonNull Context context) {
    StringBuilder sb = new StringBuilder();
    int count = 0;
    for (String permission : PERMISSIONS) {
        if (!isGranted(context, permission)) {
            if (count > 0) {
                sb.append("\n");
            }
            String info = getPermissionInfo(context, permission);
            sb.append(info);
            sb.append(";");
            count++;
        }
    }

    if (count > 0) {
        int duration;
        String message = context.getString(R.string.app_name) + " ";
        if (count == 1) {
            duration = Toast.LENGTH_SHORT;
            message += context.getString(R.string.needs_permission) + ":\n" + sb.toString();
        } else {
            duration = Toast.LENGTH_LONG;
            message += context.getString(R.string.needs_permissions) + ":\n" + sb.toString();
        }
        Utils.showToast(context, message, duration);
    }
}
 
開發者ID:kaliturin,項目名稱:BlackList,代碼行數:31,代碼來源:Permissions.java

示例10: toastText

void toastText(String text, Boolean isLong)
{
	int i;
	if (isLong)
		i = Toast.LENGTH_LONG;
	else
		i = Toast.LENGTH_SHORT;
	Toast.makeText(getApplicationContext(), text, i).show();
}
 
開發者ID:nijigenirubasho,項目名稱:mobiletailchanger,代碼行數:9,代碼來源:MainActivity.java

示例11: setDuration

@Override
public IBuilder setDuration(long durationMillis) {
    if (durationMillis < 0) {
        mBuilderDurationMillis = 0;
    }
    if (durationMillis == Toast.LENGTH_SHORT) {
        mBuilderDurationMillis = 2000;
    } else if (durationMillis == Toast.LENGTH_LONG) {
        mBuilderDurationMillis = 3500;
    } else {
        mBuilderDurationMillis = durationMillis;
    }
    return this;
}
 
開發者ID:gslovemy,項目名稱:ToastCompat,代碼行數:14,代碼來源:CustomToast.java

示例12: showToast

public static void showToast(Context context, String msg) {
    if (msg == null || "".equals(msg)) {
        return;
    }
    int duration = msg.length() > 15 ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT;
    if (mToast == null) {
        mToast = Toast.makeText(context, msg, duration);
    } else {
        mToast.setText(msg);
        mToast.setDuration(duration);
    }
    mToast.show();
}
 
開發者ID:fengdongfei,項目名稱:CXJPadProject,代碼行數:13,代碼來源:ToastUtil.java

示例13: show

public static void show(Context context, String content, int gravity, int duration) {
    long current = System.currentTimeMillis();
    //if (current < nextTimeMillis) return;
    if (mToast == null) init(context.getApplicationContext());
    mToast.setText(content);
    mToast.setDuration(duration);
    mToast.setGravity(gravity, 0, yOffset);
    nextTimeMillis = current + (duration == Toast.LENGTH_LONG ? 3500 : 2000);
    mToast.show();
}
 
開發者ID:hsj-xiaokang,項目名稱:OSchina_resources_android,代碼行數:10,代碼來源:SimplexToast.java

示例14: showMessage

/**
 * Show message to user if needed
 * @param message
 */
protected void showMessage(String message) {
    Context context = getApplicationContext();
    int duration = Toast.LENGTH_LONG;

    Toast toast = Toast.makeText(context, message, duration);
    toast.show();
}
 
開發者ID:intari,項目名稱:AndroidToolbox,代碼行數:11,代碼來源:GNSSLocationService.java

示例15: toaster

public void toaster(String message, @NonNull String duration){
    int toastDuration;
    if (duration.equals("s")){toastDuration = Toast.LENGTH_SHORT;}
    else{toastDuration = Toast.LENGTH_LONG;}
    Toast.makeText(getApplicationContext(),message,toastDuration).show();
}
 
開發者ID:amir511,項目名稱:My-Sheep,代碼行數:6,代碼來源:AddKid.java


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