本文整理汇总了Java中android.widget.Toast.setView方法的典型用法代码示例。如果您正苦于以下问题:Java Toast.setView方法的具体用法?Java Toast.setView怎么用?Java Toast.setView使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.widget.Toast
的用法示例。
在下文中一共展示了Toast.setView方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: custom
import android.widget.Toast; //导入方法依赖的package包/类
public static Toast custom(@NonNull Context context, CharSequence text, @Nullable Drawable icon,
@ColorInt int backgroundColor, int duration, @DrawableRes int resid,
@Nullable Typeface tp, float cornerRadius,
@ColorInt int textColor, float textSize) {
Toast toast = new Toast(context);
View layout = ((LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE))
.inflate(R.layout.toast_layout, null);
LinearLayout ll = (LinearLayout) layout.findViewById(R.id.base_layout);
ll.setBackgroundResource(resid);
GradientDrawable gd = (GradientDrawable) ll.getBackground().getCurrent();
gd.setColor(backgroundColor);
gd.setCornerRadius(cornerRadius);
TextView tv_message = (TextView) layout.findViewById(R.id.toast_text);
tv_message.setTextSize(textSize);
tv_message.setTypeface(tp == null ? DEFAULT_TYPEFACE : tp);
tv_message.setTextColor(textColor);
ImageView iv_toast_image = (ImageView) layout.findViewById(R.id.toast_image);
if (icon != null) {
iv_toast_image.setImageDrawable(icon);
}
tv_message.setText(text);
toast.setView(layout);
toast.setDuration(duration);
return toast;
}
示例2: showCheckmarkToast
import android.widget.Toast; //导入方法依赖的package包/类
/**
* Display a checkmark toast to notify the user of a successful scan
*/
private void showCheckmarkToast(){
// Inflate the toast layout
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.toast_checkmark,
(ViewGroup) findViewById(R.id.toast_layout_root));
TextView text = (TextView) layout.findViewById(R.id.toast_text);
text.setText(R.string.scan_successful);
// Create the toast
Toast toast = new Toast(getApplicationContext());
toast.setGravity(Gravity.CENTER_HORIZONTAL, 0, 0);
toast.setDuration(Toast.LENGTH_SHORT);
toast.setView(layout);
toast.show();
}
示例3: showToast
import android.widget.Toast; //导入方法依赖的package包/类
/**
* {@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();
}
示例4: showCenterToast
import android.widget.Toast; //导入方法依赖的package包/类
public static void showCenterToast(Context context, String title, @DrawableRes int drawableId, int duration) {
Toast toast = makeText(context.getApplicationContext(), title, duration);
toast.setGravity(Gravity.CENTER, 0, 0);
View view = LayoutInflater.from(context).inflate(R.layout.layout_center_toast, null);
LinearLayout rlContent = (LinearLayout) view.findViewById(R.id.rl_content);
TextView content = (TextView) view.findViewById(R.id.tv_content);
ImageView alertIcon = (ImageView) view.findViewById(R.id.iv_icon);
if (drawableId != 0) {
alertIcon.setVisibility(View.VISIBLE);
alertIcon.setImageResource(drawableId);
} else {
alertIcon.setVisibility(View.GONE);
}
if (!TextUtils.isEmpty(title)) {
content.setText(title);
}
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
int screenWidth = wm.getDefaultDisplay().getWidth();
int width = (int) (screenWidth / 2f);
FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) rlContent.getLayoutParams();
lp.width = width;
rlContent.setLayoutParams(lp);
rlContent.requestLayout();
toast.setView(view);
toast.show();
}
示例5: showToast
import android.widget.Toast; //导入方法依赖的package包/类
/**
* {@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();
}
示例6: show
import android.widget.Toast; //导入方法依赖的package包/类
public static void show(Context context, CharSequence text, int duration) {
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
View view = inflater.inflate(R.layout.tt_speeker_layout, null);
TextView title = (TextView) view.findViewById(R.id.top_tip);
title.setText(text);
Toast toast = new Toast(context.getApplicationContext());
toast.setGravity(
Gravity.FILL_HORIZONTAL | Gravity.TOP,
0,
(int) context.getResources().getDimension(
R.dimen.top_bar_default_height));
toast.setDuration(duration);
toast.setView(view);
toast.show();
}
示例7: create
import android.widget.Toast; //导入方法依赖的package包/类
public Toast create() {
View contentView = View.inflate(context, R.layout.dialog_toast, null);
TextView tvMsg = (TextView) contentView.findViewById(R.id.tv_toast_msg);
toast = new Toast(context);
toast.setView(contentView);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.setDuration(Toast.LENGTH_LONG);
tvMsg.setText(msg);
return toast;
}
示例8: customDisplay
import android.widget.Toast; //导入方法依赖的package包/类
private void customDisplay(String msg) {
Toast tt = new Toast(this);
LayoutInflater inflator = this.getLayoutInflater();
View vv = inflator.inflate(R.layout.custom_toast_layout, null);
TextView cTv = (TextView) vv.findViewById(R.id.cTv);
cTv.setText(msg);
vv.requestLayout();
tt.setView(vv);
tt.setGravity(Gravity.CENTER, 0, 0);
tt.show();
}
示例9: init
import android.widget.Toast; //导入方法依赖的package包/类
/**
* 初始化,单列
*
* @param context 应用级上下文
*/
public void init(Context context) {
View view = LayoutInflater.from(context).inflate(R.layout.view_toast, null);
tvToast = (TextView) view.findViewById(R.id.tv_toast);
toast = new Toast(context);
toast.setView(view);
}
示例10: show
import android.widget.Toast; //导入方法依赖的package包/类
private Toast show (int duration) {
Toast toast = Toast.makeText(mContext, mText, duration);
toast.setGravity(mGravity, xOffset, yOffset);
toast.setMargin(horizontalMargin, verticalMargin);
if (mView != null) {
toast.setView(mView);
}
toast.show();
return toast;
}
示例11: showAlertToast
import android.widget.Toast; //导入方法依赖的package包/类
/**
* Show alert toast view
*
* @param context context
* @param title title
* @param drawableId drawable Id
* @param duration duration
*/
public static void showAlertToast(Context context, String title, @DrawableRes int drawableId, int duration) {
Toast toast = makeText(context.getApplicationContext(), title, duration);
toast.setGravity(Gravity.CENTER, 0, 0);//the setting position of
View view = LayoutInflater.from(context).inflate(R.layout.layout_alert_toast, null);
LinearLayout llContent = (LinearLayout) view.findViewById(R.id.ll_content);
ImageView alertIcon = (ImageView) view.findViewById(R.id.iv_alert_icon);
TextView alertTitle = (TextView) view.findViewById(R.id.tv_alert_title);
if (drawableId != 0) {
alertIcon.setVisibility(View.VISIBLE);
alertIcon.setImageResource(drawableId);
} else {
alertIcon.setVisibility(View.GONE);
}
if (!TextUtils.isEmpty(title)) {
alertTitle.setText(title);
}
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
int screenWidth = wm.getDefaultDisplay().getWidth();
int width = (int) (screenWidth / 1.5f);
CardView.LayoutParams lp = (CardView.LayoutParams) llContent.getLayoutParams();
lp.width = width;
llContent.setLayoutParams(lp);
llContent.requestLayout();
toast.setView(view);//Set appearance
toast.show();
}
示例12: show
import android.widget.Toast; //导入方法依赖的package包/类
/**
* 显示吐司
*
* @param text 文本
* @param duration 显示时长
*/
private static void show(CharSequence text, int duration) {
cancel();
if (customView != null) {
sToast = new Toast(App.app);
sToast.setView(customView);
sToast.setDuration(duration);
} else {
sToast = Toast.makeText(App.app, text, duration);
}
sToast.setGravity(gravity, xOffset, yOffset);
sToast.show();
}
示例13: showWhiteSnackBar
import android.widget.Toast; //导入方法依赖的package包/类
public static void showWhiteSnackBar(int signed_in_message, AppCompatActivity compatActivity) {
LayoutInflater inflater = compatActivity.getLayoutInflater();
View layout = inflater.inflate(R.layout.custom_toast_view,
(ViewGroup) compatActivity.findViewById(R.id.custom_toast_container));
TextView text = (TextView) layout.findViewById(R.id.text);
text.setText(signed_in_message);
Toast toast = new Toast(compatActivity);
toast.setDuration(Toast.LENGTH_SHORT);
toast.setView(layout);
toast.show();
}
示例14: showRedTopToast
import android.widget.Toast; //导入方法依赖的package包/类
public static void showRedTopToast(@NonNull Activity activity, String text) {
View view = View.inflate(activity, R.layout.toast_error, null);
((TextView) view.findViewById(R.id.text)).setText(text);
Toast toast = Toast.makeText(activity, text, Toast.LENGTH_SHORT);
toast.setView(view);
toast.setGravity(Gravity.FILL_HORIZONTAL | Gravity.TOP, 0, 0);
toast.show();
}
示例15: show4dToast
import android.widget.Toast; //导入方法依赖的package包/类
public static void show4dToast(Context context, String text) {
if (mToast != null) {
mToast.cancel();
}
View layout = LayoutInflater.from(context).inflate(R.layout.toast_center_text, (ViewGroup) ((Activity) context).findViewById(R.id.toast_layout_root));
((TextView) layout.findViewById(R.id.text)).setText(text);
Toast toast = new Toast(context);
toast.setGravity(48, 0, 100);
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout);
toast.show();
}