繁体   English   中英

不使用按钮自动打开底页

[英]Open Bottom Sheet automatically without using a Button

我正在做这个项目,我想启动一个应用程序(主要活动),底部工作表作为了解如何使用某些功能的说明,而主要活动在后台打开。

我知道如何在底部表之间转换,但我的主要问题是第一个底部表需要一个按钮才能激活,所以我的问题是它可以在应用程序启动时自动完成而不需要按钮然后点击底部表格内的按钮后被解雇?

这是我的 Java 代码:

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


    Button buttonShow = findViewById(R.id.button_start);
    buttonShow.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {


             final BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(
                    MainActivity.this, R.style.BottomSheetDesign
            );
             View bottomSheetView = LayoutInflater.from(getApplicationContext())
                    .inflate(
                            R.layout.layout_bottom_sheet,
                            (LinearLayout)findViewById(R.id.BottomSheetContainer)
                    );
            bottomSheetView.findViewById(R.id.ButtonNext).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    final BottomSheetDialog bottomSheetDialog1 = new BottomSheetDialog(
                            MainActivity.this, R.style.BottomSheetDesign
                    );

                    View bottomSheetView1 = LayoutInflater.from(getApplicationContext())
                            .inflate(
                                    R.layout.layout_bottom_sheet1,
                                    (LinearLayout)findViewById(R.id.BottomSheetContainer1)

                            );

                    bottomSheetView1.findViewById(R.id.ButtonDone).setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {

                            bottomSheetDialog1.dismiss();

                        }

                    });

                    bottomSheetDialog.dismiss();
                    bottomSheetDialog1.setContentView(bottomSheetView1);
                    bottomSheetDialog1.show();

                }
            });

            bottomSheetDialog.setContentView(bottomSheetView);
            bottomSheetDialog.show();

        }

    });

在oncreate方法中直接调用bottomsheet

试试这个代码:

 @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    openBottomSheet();
}

private void openBottomSheet() {

    final BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(
            MainActivity.this, R.style.BottomSheetDesign
    );
    View bottomSheetView = LayoutInflater.from(getApplicationContext())
            .inflate(
                    R.layout.layout_bottom_sheet,
                    (LinearLayout) findViewById(R.id.BottomSheetContainer)
            );
    bottomSheetView.findViewById(R.id.ButtonNext).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            final BottomSheetDialog bottomSheetDialog1 = new BottomSheetDialog(
                    MainActivity.this, R.style.BottomSheetDesign
            );

            View bottomSheetView1 = LayoutInflater.from(getApplicationContext())
                    .inflate(
                            R.layout.layout_bottom_sheet1,
                            (LinearLayout) findViewById(R.id.BottomSheetContainer1)

                    );

            bottomSheetView1.findViewById(R.id.ButtonDone).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    bottomSheetDialog1.dismiss();

                }

            });

            bottomSheetDialog.dismiss();
            bottomSheetDialog1.setContentView(bottomSheetView1);
            bottomSheetDialog1.show();

        }
    });

    bottomSheetDialog.setContentView(bottomSheetView);
    bottomSheetDialog.show();
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM