Search code examples
androidandroid-activityonclicklistenersubmenufloating-action-button

How to add actions to menu buttons in floating action button in android


I am trying to create a floating action button in android and want to add actions to those small sub buttons to start new activity by clicking them. I successfully managed to create those sub buttons but cannot assign action to them to start new activity.


Solution

  • I'm not sure i have understand what you want to do.. but seems you want simple open a new activity onClick.. so you can do in this way:

    Button floatingBtn = (Button)findViewById(R.id.fab);
    floatingBtn.setOnClickListener = new(view.onClickListener()
    {
        Intent i = new Intent(this, Activity.class);
        startActivity(i);
    
    });
    

    Remember to insert the new activity in the manifest