0
我正在構建一個應用程序,並希望在彈出窗口中更改團隊顏色。我使用ImageButtons向用戶顯示團隊顏色。主要活動中的一個按鈕和彈出窗口中的四個按鈕。當我在彈出窗口中單擊一個時,我可以切換背景,但當我關閉彈出窗口並再次打開時,彈出窗口中的按鈕已被複位。在彈出窗口中更改ImageButton的背景
如何在沒有重置的情況下關閉彈出窗口?
public void colorchange(final View view){
layoutInflater = (LayoutInflater) getApplicationContext().getSystemService(LAYOUT_INFLATER_SERVICE);
ViewGroup container = (ViewGroup) layoutInflater.inflate(R.layout.popwindow, null);
relativeLayout = (RelativeLayout) findViewById(R.id.popup);
popupWindow = new PopupWindow(container, relativeLayout.getWidth(), relativeLayout.getHeight(), true);
popupWindow.showAtLocation(relativeLayout, Gravity.NO_GRAVITY, (int)relativeLayout.getX(),(int)relativeLayout.getY());
ImageButton narancs = (ImageButton) container.findViewById(R.id.imgbutton1);
container.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
popupWindow.dismiss();
return false;
}
});
narancs.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Drawable asds = v.getBackground();
Log.d("hatter", String.valueOf(asds));
v.setBackgroundResource(R.drawable.bluebutton);
view.setBackgroundResource(R.drawable.orangebutton);
Log.d("hatter", String.valueOf(view.getBackground()));
//popupWindow.dismiss();
}
});
}
此代碼在mainactivity按鈕單擊事件上運行。