Set FloatingActionButton size on Android

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 FloatingActionButton button on Android but I can not set the size of the button or something like app:fabSize="mini" because it does not have the setSize method and neither Enum FloatingActionButton.SIZE_MINI .     

asked by anonymous 29.06.2017 / 23:45

1 answer

2

You can programmatically use the setSize yes method using the lib com.android.support:design:25.3.1 . The setting should look like this below:

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

Or

fab.setSize(FloatingActionButton.SIZE_NORMAL);

You should import lib :

import android.support.design.widget.FloatingActionButton;

No Gradle :

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

See more details in the documentation . p>     

30.06.2017 / 03:33