2014-02-27 78 views
0
sas12.setOnClickListener(new View.OnClickListener() { 
    @Override 
    public void onClick(View view) { 
     // TODO Auto-generated method stub"                 " 
     Toast toast= Toast.makeText(getApplicationContext(), 
       "                 ", 
       Toast.LENGTH_SHORT); 
     toast.setGravity(Gravity.CENTER, 0, 0); 
     LinearLayout toastView = (LinearLayout) toast.getView(); 
     ImageView imageCodeProject = new ImageView(getApplicationContext()); 
     imageCodeProject.setImageResource(R.drawable.flushed_skin); 
     toast.setView(view); 
     toast.show(); 
     toastView.addView(imageCodeProject, 0); 
     toast.show();    
    } 
}); 

如何調整高度並使此吐司碼的透明度爲透明。如何調整高度並使該吐司碼的透明度爲透明。

回答

0

我還沒有嘗試修改默認Toast,但可以爲Toast創建自定義佈局,然後在佈局文件中設置android:alpha。

靜態調用,這樣就可以從任何地方調用它:

public static void showDialog(Context context, String text) 
{ 

    LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 

    View toastLayout = inflater.inflate(R.layout.toast_custom, null); 

    // Notify the user 
    TextView textView = (TextView) toastLayout.findViewById(R.id.text); 
    textView.setText(text);    
    Toast toast = new Toast(context); 
    toast.setDuration(1000); 
    toast.setGravity(Gravity.CENTER, 0, 0); 
    toast.setView(toastLayout); 
    toast.show();    

} 

佈局文件toast_custom.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/toast_layout_root" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="horizontal" 
android:padding="20dp"  
android:alpha="0.5" 
>  

<TextView   
    android:id="@+id/text" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center" 
    android:textColor="#000" 
    android:textSize="24sp" 
    android:textStyle="bold"   
    /> 

+0

但這吐司保持圖像@ Maurice – user3350245

+0

您可以調整我的示例,並將ImageView放在佈局中而不是的TextView –