2011-01-16 4 views

Antwort

56

sollte diese Arbeit:

Toast t = Toast.makeText(this, "Hello", Toast.LENGTH_SHORT); 
t.setGravity(Gravity.FILL_HORIZONTAL, 0, 0); 
+0

Das funktioniert gut, aber der Toast wird als center_horizental angezeigt. Können wir Fill_Horizontal und BOTTOM zusammen haben? –

+0

funktioniert wie ein Charme, Danke @ C0deAttack –

+1

@KaiWang können Sie einfach hinzufügen | Operator wie folgt: toast.setGravity (Gravity.FILL_HORIZONTAL | Gravity.BOTTOM, 0, 0); – Cody

0

Ich würde sagen, Sie sollten einen Dialog oder eine Aktivität machen (mit dem Dialog-Thema oder etwas, das Sie gemacht haben, das wie das Dialog-Thema aussieht), und zeigen Sie das.

Verwenden Sie einen Timer im oncreate, der finish() aufruft, nachdem Ihre Zeit abgelaufen ist.

0

so etwas wie dieses Try ...

wM = (WindowManager) context.getApplicationContext() 
       .getSystemService(Context.WINDOW_SERVICE); 
     mParams = new WindowManager.LayoutParams(); 
     LayoutInflater inflate = (LayoutInflater) context 
       .getApplicationContext().getSystemService(
         Context.LAYOUT_INFLATER_SERVICE); 
     v = inflate.inflate(R.layout.custom_toast, null); 
     // Set the layout to be like a toast window! 
    mParams.gravity = Gravity.WHEREVER YOU WANT IT TO BE 
      mParams.height = 200; 
    mParams.width = WindowManager.LayoutParams.FILL_PARENT; 
    mParams.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL; 
    mParams.format = PixelFormat.OPAQUE; 
    mParams.type = WindowManager.LayoutParams.TYPE_TOAST; 

      wm.addView(v); 

      <Timer or whatever> 

      wm.removeView(v); 
1

Werfen Sie einen Blick auf diese example für Custom Toast mit Border.

2

Sie können Toast mit benutzerdefiniertem Layout und fill_horizontal erstellen. Der folgende Code ist in der Adapter-Klasse geschrieben und es funktioniert gut.

  LayoutInflater inflater =(LayoutInflater)mContext 
            .getSystemService(mContext.LAYOUT_INFLATER_SERVICE); 
      View layout =inflater.inflate(R.layout.custom_toast_layout,null); 

      TextView text = (TextView) layout.findViewById(R.id.text); 
      text.setText("Hello! This is a custom toast!"); 

      Toast toast = new Toast(mContext); 

      //use both property in single function 
      toast.setGravity(Gravity.BOTTOM|Gravity.FILL_HORIZONTAL, 0, 0); 
      toast.setDuration(Toast.LENGTH_LONG); 
      toast.setView(layout); 
      toast.show(); 
Verwandte Themen