【发布时间】:2016-03-31 04:52:28
【问题描述】:
我正在 Android Studio 中制作应用程序。在我的一个活动中,有一堆按钮,当您单击一个时,会出现一个 PopupWindow 类,上面有 4 个不同颜色的按钮。
我遇到的问题:出现 PopupWindow 后,我希望用户选择 4 个按钮中的一个,并根据他们选择的一种颜色,第一次单击活动的原始按钮将更改其背景颜色到弹出窗口中选择的那个。
弹出代码:
public class Pop extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.popupwindow);
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
int width = dm.widthPixels;
int height = dm.heightPixels;
getWindow().setLayout((int)(width*.7), (int)(height*.7));
final Button color1Button = (Button) findViewById(R.id.redbutton);
color1Button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
}
}
主要活动代码:
Button a = (Button) findViewById(R.id.button);
a.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(LambertsLaneSection1Activity.this, Pop.class));
}
});
Button b = (Button) findViewById(R.id.button3);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(LambertsLaneSection1Activity.this, Pop.class));
}
});
Button c = (Button) findViewById(R.id.button4);
c.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(LambertsLaneSection1Activity.this, Pop.class));
}
});
【问题讨论】:
标签: java android class button android-studio