2012-12-05 4 views
1

팝업이 있습니다. 내가 동적 android:background="@drawable/popup_bg"에서 여기 android:background="@drawable/popup_bg2"팝업 창의 선형 레이아웃 배경을 동적으로 설정하는 방법은 무엇입니까?

에 팝업 윈도우의 LinearLayout의 배경을 변경하려는 것은 내 코드입니다 :

private void showPopup(final Activity context, int x, int y, String id, String n, String a, String l) { 
    int popupWidth = 200; 
    int popupHeight = 150; 

    // Inflate the popup_layout.xml 
    LinearLayout viewGroup = (LinearLayout) context.findViewById(R.id.popup); 


    LayoutInflater layoutInflater = (LayoutInflater) context 
    .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    View layout = layoutInflater.inflate(R.layout.popup_layout, viewGroup); 

    TextView id1 = (TextView) layout.findViewById(R.id.id); 
    TextView name = (TextView) layout.findViewById(R.id.name); 
    TextView absent = (TextView) layout.findViewById(R.id.absence); 
    TextView late = (TextView) layout.findViewById(R.id.lateness); 

    id1.setText(id); 
    name.setText(n); 
    absent.setText(a); 
    late.setText(l); 

    // Creating the PopupWindow 
    final PopupWindow popup = new PopupWindow(context); 
    popup.setContentView(layout); 
    popup.setWidth(popupWidth); 
    popup.setHeight(popupHeight); 
    popup.setFocusable(true); 

    // Some offset to align the popup a bit to the right, and a bit down, relative to button's position. 
    int OFFSET_X = 30; 
    int OFFSET_Y = 300; 

    // Clear the default translucent background 
    popup.setBackgroundDrawable(new BitmapDrawable()); 

    // Displaying the popup at the specified location, + offsets. 
    popup.showAtLocation(layout, Gravity.NO_GRAVITY, x + OFFSET_X, y +OFFSET_Y); 

    // Getting a reference to Close button, and close the popup when clicked. 
    Button close = (Button) layout.findViewById(R.id.close); 
    close.setOnClickListener(new OnClickListener() { 

    public void onClick(View v) { 
     popup.dismiss(); 
    } 
    }); 
} 

popup_layout.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:id="@+id/popup" 
    android:layout_height="wrap_content" 
    android:background="@drawable/popup_bg" 
    android:orientation="vertical" > 
</LinearLayout> 

답변

3

이 시도

 LinearLayout ll=popup.getContentView().findViewById(R.id.popup); 
    ll.setBackgroundResource(R.drawable.yourImage); 

이 제공되면이 작업을 수행하십시오.위의 작업을 수행하기 전에을 입력하십시오.