2011-01-16 2 views

답변

56

이 작동합니다.

+0

괜찮 으면 작동하지만 토스트는 center_horizental으로 표시됩니다. Fill_Horizontal과 Bottom을 함께 사용할 수 있습니까? –

+0

는 매력처럼 작동합니다. 감사합니다. @ C0deAttack –

+1

@ 카이 웡 당신은 방금 추가 할 수 있습니다. 연산자는 다음과 같습니다 : toast.setGravity (Gravity.FILL_HORIZONTAL | Gravity.BOTTOM, 0, 0); – Cody

0

대화 또는 대화 (대화 상자 테마 또는 대화 상자 테마처럼 보이는 대화 상자)를 만들어야한다고 말하고 싶습니다.

시간이 끝난 후 을 호출하는 oncreate의 타이머를 사용하십시오. ...

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

이런 식으로 뭔가를 시도

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

테두리가있는 맞춤 토스트에 대해 example을보십시오.

2

사용자 정의 레이아웃 및 fill_horizontal을 사용하여 토스트를 생성 할 수 있습니다. 아래 코드는 Adapter 클래스로 작성되었으며 제대로 작동합니다.

  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(); 
관련 문제