简体   繁体   中英

How I can show other Views if I click on the FloatingActionButton?

I have a FloatingActionButton in my Android application. If I click on this button I want to get an OptionMenu with a slider and a button inside it.

Here is my code:

@Override
    public void onStart(){
        super.onStart();
        FloatingActionButton fab = (FloatingActionButton) getView().findViewById(R.id.fab);

        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

//Here I want to show a slider and a button. not a Snackbar


                //Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                  //      .setAction("Action", null).show();
            }
        });
    }

try this

fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                 // add this line
                 openOptionsMenu(); 
            }
        });

I assume by slider you mean slider Menu,

 fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (drawer.isDrawerOpen(GravityCompat.START)) {
                drawer.closeDrawer(GravityCompat.START);
            } else {
                drawer.openDrawer(GravityCompat.START);
            }
            //Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
            //        .setAction("Action", null).show();
        }
    });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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