我想在我的 MainActivity 中打开自定义弹出类来更改活动。我还想关闭我的MainActivity 。 意图是红色的,怎么解决?
public class PopActivity extends Activity {
Button btn_close;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pop);
btn_close = findViewById(R.id.btn_close);
btn_close.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(PopupMenu.this, MainActivity.class);
finish();
}
});
DisplayMetrics dn = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dn);
int width = dn.widthPixels;
int height = dn.heightPixels;
getWindow().setLayout((int)(width*.9), (int)(height*.3));
WindowManager.LayoutParams params = getWindow().getAttributes();
params.gravity = Gravity.CENTER;
params.x = 0;
params.y = 450;
getWindow().setAttributes(params);
}