私はアプリケーションを構築していて、ポップアップウィンドウでチームカラーを変更したいと考えています。私はImageButtonsを使用して、ユーザーにチームカラーを示しました。メインアクティビティの1つのボタンと、ポップアップウィンドウの4つのボタン。ポップアップウィンドウでクリックすると背景を切り替えることができますが、ポップアップウィンドウを閉じてもう一度開くと、ポップアップウィンドウのボタンがリセットされます。ポップアップウィンドウで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ボタンのクリックイベントで実行されます。