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