简体   繁体   English

如果单击FloatingActionButton,如何显示其他视图?

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

I have a FloatingActionButton in my Android application. 我的Android应用程序中有一个FloatingActionButton If I click on this button I want to get an OptionMenu with a slider and a button inside it. 如果单击此按钮,我想获得一个带有滑动条和其中一个按钮的OptionMenu

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();
        }
    });

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

相关问题 如何在 FloatingActionButton 上方制作此 TextView? - How can I make this TextView above the FloatingActionButton? 如何显示彼此相邻的两个文本视图 - How do I show two text views next to each other 我有两个水平滚动视图。 如何一次显示一个,并在单击按钮时在它们之间切换? - I have two horizontal scroll views. How can I show one at a time and switch between them on button click? 我可以在Android中将FloatingActionButton投射到ImageButton吗? - Can I cast FloatingActionButton to ImageButton in Android? 如何将两个视图堆叠在一起? - How can I stack two views on top of each other? 如何在布局中包含 listView 以及布局中的其他视图 - How can I include listView in a layout with other views in the layout already 在viewpager中查看所有视图后,如何显示按钮? - How can I show a button when all views are viewed in viewpager? 如何在Spinner Android单击中显示和隐藏按钮 - how i can show and hide button in click on spinner android 如何在其他窗格中显示面板? - How can i show my panels in the other panes? 如何使 android 中的按钮出现在固定的 position 中并始终位于所有其他视图的前面? - How can i make a Button in android appear in a fixed position and always in front of all other views?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM