在启动MainActivity之前,如何启动布局mydialog?

时间:2018-10-18 22:59:04

标签: java android main-activity

在启动MainActivity之前,我如何尝试过布局布局对话框,我尝试了很多事情,但都无济于事,是否可以在不修改Android清单中的启动器的情况下启动此布局?预先感谢您的帮助。

公共类MainActivity扩展了AppCompatActivity {     对话框mydialog;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mydialog = new Dialog(this);
    Button button =(Button)findViewById(R.id.button);
    Button button2 =(Button)findViewById(R.id.button2);
    Button button3 =(Button) findViewById(R.id.button3);
    Button button4=(Button) findViewById(R.id.button4);
    Button button5 =(Button) findViewById(R.id.button5);
    Button button6 =(Button) findViewById(R.id.button6);
    Button button7 =(Button) findViewById(R.id.button7);
    Button button8 =(Button) findViewById(R.id.button8);
    Button button9 =(Button) findViewById(R.id.button9);
    Button button10 =(Button) findViewById(R.id.button10);
    Button button11 =(Button) findViewById(R.id.button11);

    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent int1= new Intent(MainActivity.this,buttActivity.class);
            startActivity(int1);
        }
    });
    button2.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent int2= new Intent(MainActivity.this,butt2Activity.class);
            startActivity(int2);          }
    });
    button3.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent int3 = new Intent(MainActivity.this, butt3Activity.class);
            startActivity(int3);
        }
    });
    button4.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent int4 = new Intent(MainActivity.this, butt4Activity.class);
            startActivity(int4);
        }
    });
    button5.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent int5 = new Intent(MainActivity.this, butt5Activity.class);
            startActivity(int5);
        }
    });
    button6.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent int6 = new Intent(MainActivity.this, butt6Activity.class);
            startActivity(int6);
        }
    });
    button7.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent int7 = new Intent(MainActivity.this, butt7Activity.class);
            startActivity(int7);
        }
    });
    button8.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent int8 = new Intent(MainActivity.this, butt8Activity.class);
            startActivity(int8);
        }
    });
    button9.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent int9 = new Intent(MainActivity.this, butt9Activity.class);
            startActivity(int9);
        }
    });
    button10.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent int10 = new Intent(MainActivity.this, butt10Activity.class);
            startActivity(int10);
        }
    });
    button11.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent int11 = new Intent(MainActivity.this, butt11Activity.class);
            startActivity(int11);
        }
    });



}
public void Showpopup (View v) {
    TextView txtofclose;
    mydialog.setContentView(R.layout.activity_main2);
    txtofclose = (TextView) mydialog.findViewById(R.id.txtofclose);
    txtofclose.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mydialog.dismiss();
        }
    });
    mydialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    mydialog.show();
}

}

1 个答案:

答案 0 :(得分:0)

有几种方法可以完成此任务,而我目前无法进行任务。

  1. 在主要活动中添加框架布局以指示布局
  2. 添加另一个活动并保留布局。然后具有一个共享首选项,该首选项带有一个标志,您将检查是否已设置(如果未在首次运行时设置)。在应用启动时检查是否在共享首选项中设置了标志
  3. 找出在对话框中放置免责声明的方法