2011-11-28 1 views
4

저는 사용자 정의 토스트를 그리드 뷰에 배치하고 너비를 제어해야하기 때문에 주로 사용자 정의 토스트를 만듭니다. 하지만 표준 토스트에서 라이트 블루 후광을 정말 좋아해요. 그리고 그걸 다시 얻고 싶습니다. (또는 적어도 내 토스트 토스트가 기본 토스트와 다소 비슷합니다.)커스텀 토스트에서 건배의 연두색 후광을 어떻게 얻을 수 있습니까?

달성하기 쉬운 방법은 무엇인가요? .

내가이 레이아웃에서 사용자 정의 토스트 만들어 :

<LinearLayout 
     android:id="@+id/toast_layout_root" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:orientation="horizontal" android:padding="10dp"> 
     <ImageView android:id="@+id/toast_layout_image" 
      android:layout_width="wrap_content" android:layout_height="wrap_content" 
      android:src="@drawable/icon" android:layout_marginRight="10dp"> 
     </ImageView> 
     <TextView android:layout_width="wrap_content" 
      android:layout_height="wrap_content" android:id="@+id/toast_layout_text"   
      android:textColor="#FFF" android:textAppearance="?android:attr/textAppearanceLarge"> 
     </TextView> 
    </LinearLayout> 

과이 방법 (안드로이드 디바이스에 설명 된대로 일반적인 방법을 호출 문서뿐만 아니라 웹에 자습서의 몇 가지를, 유일한 차이점은 나는)의 격자 타일의 위치에 따라 격자보기로 작업하고 각 토스트가 배치됩니다 :

int location[] = new int[2]; 
view.getLocationOnScreen(location); 
LayoutInflater inflater = getLayoutInflater(); 
View toastLayout = inflater.inflate(R.layout.toast_layout,(ViewGroup)findViewById(R.id.toast_layout_root)); 
TextView textView = (TextView) toastLayout.findViewById(R.id.toast_layout_text); 
textView.setText("This tile does not contain any valid data."); 
int toastWidth = cellWidth * 3/4; 
textView.setWidth(toastWidth - 64); // TODO picture size needs to be correct 

Toast toast = new Toast(getApplicationContext()); 
toast.setView(toastLayout); 
toast.setDuration(Toast.LENGTH_SHORT); 
toast.setGravity(Gravity.TOP|Gravity.LEFT, location[0]+((cellWidth-toastWidth)/2),location[1]+cellHeight-100);    
toast.show(); 

이 매우 깨끗하지만 기본 토스트는 전혀 다른 모습 ..

답변

4

당신의 토스트 메시지를이 레이아웃을 적용

<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:padding="35dp" 
     android:orientation="horizontal" 
     android:background="@android:drawable/dialog_holo_dark_frame" > 
     <ImageView android:id="@+id/toast_layout_image" 
      android:layout_width="wrap_content" android:layout_height="wrap_content" 
      android:src="@drawable/appicon" android:layout_marginRight="10dp"> 
     </ImageView> 
     <TextView android:layout_width="wrap_content" 
      android:layout_height="wrap_content" android:id="@+id/toast_layout_text"   
      android:textColor="#FFF" android:textAppearance="?android:attr/textAppearanceLarge"> 
     </TextView> 
    </LinearLayout> 

을 나는 무슨 일이 cellWidth 및 cellHeight, 그래서 그것은
편집에 적합하지 않을 경우 패딩을 실험하려고 발견하지 않습니다 아, 나는 어두운 테마를 적용 대신 빛을 사용하십시오.

+0

배경에 대한 올바른 참조는 "@android : drawable/toast_frame"입니다 (http://androiddrawableexplorer.appspot.com/ 여기에 모든 안드로이드 드로어 목록이 있습니다). – EtienneSky

관련 문제