title: Android Studio - Custom Toast Not Showing
body: <p>I watched many videos and tried them all one by one. But I didn't get any positive results. I'm not getting an error. The message is not displayed. I could not identify where the problem was. I request help on the subject.</p>
  <p>I also share the code blocks and XML designs I have used with you. I can't find where I went wrong.</p>
  <p>Thanks.</p>
  <p>Custom Toast Class:</p>
  <pre><code>public class CustomToast {
  Context context;
  LayoutInflater inflater;
  View view;
  View singleToast_color;
  
  public CustomToast(Context context) {
      this.context = context;
      this.inflater = ((Activity) context).getLayoutInflater();
  }
  
  
  public void Information(String message) {
      try {
          //  GetLayout
          view = LayoutInflater.from(context).inflate(R.layout.single_toast, (ViewGroup) ((Activity) context).findViewById(R.id.singleToast_root));
          //  Initialize
          singleToast_color = view.findViewById(R.id.singleToast_color);
          ImageView singleToast_iv = view.findViewById(R.id.singleToast_iv);
          TextView singleToast_lbl_message = view.findViewById(R.id.singleToast_lbl_message);
          //  SetColor And Value
          singleToast_color.setBackgroundColor(context.getResources().getColor(R.color.toastInformation));
          singleToast_iv.setImageResource(R.drawable.ic_information);
          //  Set Value
          singleToast_lbl_message.setText(message);
  
          //  Create Toast
          Toast toast = new Toast(context);
          toast.setDuration(Toast.LENGTH_LONG);
          toast.setView(view);
          toast.show();
  
      } catch (Exception exception) {
          exception.printStackTrace();
      }
  }
  </code></pre>
  <p>Single Toast Layout:</p>
  <p><a href="https://i.stack.imgur.com/ZKW3y.png" rel="nofollow noreferrer">Show XML Output</a></p>
  <pre><code>    &lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;androidx.cardview.widget.CardView xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
      xmlns:tools=&quot;http://schemas.android.com/tools&quot;
      android:id=&quot;@+id/singleToast_root&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;wrap_content&quot;
      android:layout_marginStart=&quot;30dp&quot;
      android:layout_marginEnd=&quot;30dp&quot;
      app:cardCornerRadius=&quot;10dp&quot;&gt;
  
      &lt;androidx.constraintlayout.widget.ConstraintLayout
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;wrap_content&quot;&gt;
  
          &lt;LinearLayout
              android:layout_width=&quot;0dp&quot;
              android:layout_height=&quot;wrap_content&quot;
              android:baselineAligned=&quot;false&quot;
              android:orientation=&quot;horizontal&quot;
              android:weightSum=&quot;2&quot;
              app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
              app:layout_constraintEnd_toEndOf=&quot;parent&quot;
              app:layout_constraintStart_toStartOf=&quot;parent&quot;
              app:layout_constraintTop_toTopOf=&quot;parent&quot;&gt;
  
              &lt;View
                  android:id=&quot;@+id/singleToast_color&quot;
                  android:layout_width=&quot;0dp&quot;
                  android:layout_height=&quot;match_parent&quot;
                  android:layout_weight=&quot;0.1&quot;
                  android:background=&quot;#007CC8&quot; /&gt;
  
              &lt;androidx.constraintlayout.widget.ConstraintLayout
                  android:layout_width=&quot;0dp&quot;
                  android:layout_height=&quot;wrap_content&quot;
                  android:layout_weight=&quot;1.9&quot;
                  android:paddingTop=&quot;15dp&quot;
                  android:paddingBottom=&quot;15dp&quot;&gt;
  
                  &lt;ImageView
                      android:id=&quot;@+id/singleToast_iv&quot;
                      android:layout_width=&quot;wrap_content&quot;
                      android:layout_height=&quot;wrap_content&quot;
                      android:layout_marginStart=&quot;10dp&quot;
                      android:src=&quot;@drawable/ic_information&quot;
                      app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
                      app:layout_constraintStart_toStartOf=&quot;parent&quot;
                      app:layout_constraintTop_toTopOf=&quot;parent&quot;
                      app:layout_constraintVertical_bias=&quot;0.5&quot;
                      tools:ignore=&quot;ContentDescription&quot; /&gt;
  
                  &lt;TextView
                      android:id=&quot;@+id/singleToast_lbl_message&quot;
                      android:layout_width=&quot;0dp&quot;
                      android:layout_height=&quot;0dp&quot;
                      android:layout_marginStart=&quot;10dp&quot;
                      android:layout_marginEnd=&quot;10dp&quot;
                      android:fontFamily=&quot;@font/unisans_regular&quot;
                      android:gravity=&quot;center|start&quot;
                      android:text=&quot;Bilgi Mesajı Deneme&quot;
                      android:textAlignment=&quot;textStart&quot;
                      android:textSize=&quot;15sp&quot;
                      app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
                      app:layout_constraintEnd_toEndOf=&quot;parent&quot;
                      app:layout_constraintStart_toEndOf=&quot;@+id/singleToast_iv&quot;
                      app:layout_constraintTop_toTopOf=&quot;parent&quot; /&gt;
  
              &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
  
          &lt;/LinearLayout&gt;
  
      &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
  
  &lt;/androidx.cardview.widget.CardView&gt;
  </code></pre>
  <p>Usage:</p>
  <pre><code>@Override
  public View onCreateView(@NonNull LayoutInflater inflater,
                           ViewGroup container, Bundle savedInstanceState) {
      if (binding == null) {
          binding = FragmentCoinsBinding.inflate(inflater, container, false);
          init();
          objectListener();
          getCoinInformationList();
          CustomToast customToast = new CustomToast(binding.getRoot().getContext());
          customToast.Information(&quot;Hi There !&quot;);
      }
      return binding.getRoot();
  }
  </code></pre>
  <p>Logcat:</p>
  <pre><code>2021-05-14 20:01:23.352 511-2086/system_process W/NotificationService: Toast already killed. pkg=com.xxx.yyy token=android.os.BinderProxy@7f5c8ec
  2021-05-14 20:02:41.352 511-2831/system_process W/NotificationService: Toast already killed. pkg=com.xxx.yyy token=android.os.BinderProxy@e0d6177
  2021-05-14 20:02:43.340 511-652/system_process W/NotificationService: Toast already killed. pkg=com.xxx.yyy token=android.os.BinderProxy@f1a0981
  2021-05-14 20:07:13.873 511-4668/system_process W/NotificationService: Toast already killed. pkg=com.xxx.yyy token=android.os.BinderProxy@a02aac5
  2021-05-14 20:08:13.844 511-2086/system_process W/NotificationService: Toast already killed. pkg=com.xxx.yyy token=android.os.BinderProxy@d2a310c
  2021-05-14 20:08:32.580 511-1805/system_process W/NotificationService: Toast already killed. pkg=com.xxx.yyy token=android.os.BinderProxy@267d652
  </code></pre>