通过弹出客户类别更改活动

时间:2019-02-09 19:57:31

标签: java android-studio

我想在我的 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);
}

0 个答案:

没有答案