Set Floatingactionbutton size on Android

Asked

Viewed 391 times

0

private FloatingActionButton createButton(int id) {

    FloatingActionButton fab = new FloatingActionButton(this);

    fab.setId(id);

    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            System.out.println("Entrei truta");
        }
    });
    fab.setImageResource(R.drawable.ic_delete);
    RelativeLayout.LayoutParams lay = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
        ViewGroup.LayoutParams.WRAP_CONTENT);
    lay.addRule(RelativeLayout.BELOW, buttonAddCardapio.getId());
    lay.addRule(RelativeLayout.RIGHT_OF, editTextCardapioHora.getId());
    lay.addRule(RelativeLayout.END_OF, editTextCardapioHora.getId());

    fab.setLayoutParams(lay);

    return fab;    
}

I’m trying to create a button FloatingActionButton on Android but I can’t set the size of the button or something like that app:fabSize="mini" because it does not have the method setSize and neither the Enum FloatingActionButton.SIZE_MINI.

1 answer

2


Programmatically you can use the method setSize yes using the lib com.android.support:design:25.3.1. The definition should be this way below:

FloatingActionButton fab = new FloatingActionButton(this);
fab.setSize(FloatingActionButton.SIZE_MINI);

Or

fab.setSize(FloatingActionButton.SIZE_NORMAL);

You must care to lib:

import android.support.design.widget.FloatingActionButton;

In the Gradle:

compile 'com.android.support:design:25.3.1'

See more details in the documentation.

  • This option does not appear here. I tried using maybe it could be version

  • @Victorcésar managed to solve the problem?!

  • 1

    I managed to solve the problem. I was on sdk 23 I changed to 25 and so the methods appeared.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.