を示さないことがある理由はないshow.Doesを行ういずれかを知っているは、[システムのトースト通知の許可を無効にし、アンドロイド5.0 +で
ここではコードです:?
Toast.makeText(context, msg, Toast.LENGTH_LONG).show();
を示さないことがある理由はないshow.Doesを行ういずれかを知っているは、[システムのトースト通知の許可を無効にし、アンドロイド5.0 +で
ここではコードです:?
Toast.makeText(context, msg, Toast.LENGTH_LONG).show();
これはあなたの問題の解決策ではありませんが、誤ってアプリケーションの「通知を表示する」設定を一度オフにしました。あなたのデバイス設定/アプリケーション/マネージャーに入り、この設定をチェックすることが考えられます。
あなたの助けていただきありがとうございますが、私はAndroid Devoleperです。解決策が私の問題を解決できない場合があります。 –
新しいToast
クラスを作成するためのソリューションが見つかりました。
トースト
public class Toast {
private Context mContext;
private WindowManager wm;
private int mDuration;
private View mNextView;
public static final int LENGTH_SHORT = 1500;
public static final int LENGTH_LONG = 3000;
public Toast(Context context) {
mContext = context.getApplicationContext();
wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
}
public static Toast makeText(Context context, CharSequence text,
int duration) {
Toast result = new Toast(context);
View view = android.widget.Toast.makeText(context, text, android.widget.Toast.LENGTH_SHORT).getView();
if (view != null){
TextView tv = (TextView) view.findViewById(android.R.id.message);
tv.setText(text);
}
result.mNextView = view;
result.mDuration = duration;
return result;
}
public static Toast makeText(Context context, int resId, int duration)
throws Resources.NotFoundException {
return makeText(context, context.getResources().getText(resId),duration);
}
public void show() {
if (mNextView != null) {
WindowManager.LayoutParams params = new WindowManager.LayoutParams();
params.gravity = Gravity.CENTER | Gravity.CENTER_HORIZONTAL;
params.height = WindowManager.LayoutParams.WRAP_CONTENT;
params.width = WindowManager.LayoutParams.WRAP_CONTENT;
params.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
| WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
params.format = PixelFormat.TRANSLUCENT;
params.windowAnimations = android.R.style.Animation_Toast;
params.y = dip2px(mContext, 64);
params.type = WindowManager.LayoutParams.TYPE_TOAST;
wm.addView(mNextView, params);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
if (mNextView != null) {
wm.removeView(mNextView);
mNextView = null;
wm = null;
}
}
}, mDuration);
}
}
/**
* dip2px
*
* @param context
* @param dipValue
* @return int
*
*/
private int dip2px(Context context, float dipValue) {
final float scale = context.getResources().getDisplayMetrics().density;
return (int) (dipValue * scale + 0.5f);
}
}
XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/waiting_bg"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:id="@+id/tvMsg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textColor="@color/mColor_white"
android:textSize="15sp"/>
は、回答を貼り付ける必要があります。最後にリンクを追加してください –
コメントありがとうございます@ SharartiKAKA – KeLiuyue
この問題を解決してくれたこのメソッドは、@ KeLiuyue –
チェックこの - https://issuetracker.google.com/issues/36951147 – Rahul
私はそれがそのように設計されており、どのよう –
おかげで私は見てみましょうそれを解決するために、なぜこれは、二つの異なるものであるべきだと思います。 Rahul –