zendesk / android-floating-action-button

Floating Action Button for Android based on Material Design specification
Apache License 2.0
6.38k stars 1.45k forks source link

hepl for "setTitle" method #259

Open DamineBO opened 9 years ago

DamineBO commented 9 years ago

Hello ! Fist of all I want to thank you so much for this useful library. My problem here is that I want to add a fab menu with some fab buttons in my activity.java not in xml file :

FloatingActionsMenu menu = new FloatingActionsMenu(this);
FloatingActionButton button = new FloatingActionButton(this);
        menu_container.addView(menu);
        button.setTitle("btn_title");
        button.setIcon(R.mipmap.btn_icon);
        menu.addButton(button);

screenshot_2015-10-02-14-35-23

There is no title like in the screenshot :(

Can you help to fix this please :) I don't want to fix this in the xml file

MaherSakka commented 9 years ago

You have to set the attributes fab:fab_labelStyle and fab:fab_labelsPosition in your view layout. Good Luck !

DamineBO commented 9 years ago

@MaherSakka Thanks for replying however I don't want to add these fab buttons in XML, I want to add them in my java code. I think that this is the right code :

button.setTitle("btn_title");

And I dont know why this don't works with me

nishantjain91 commented 9 years ago

I also had the same problem. What worked me for me was adding button to menu after setting the text using setTitle().

xiang-xx commented 8 years ago

In FloatingActionsMenu:

@Override protected void onFinishInflate() {

super.onFinishInflate();

bringChildToFront(mAddButton);
mButtonsCount = getChildCount();

if (mLabelsStyle != 0) {   

// here is important. // As MaherSakka said, you should set the attributes fab:fab_labelStyle and fab:fab_labelsPosition in //your view layout !!! for FloatingActionsMenu !!!. //,otherwise, it will not create lables for you button

  createLabels();
}

}

ravenns commented 8 years ago

Hello all, I must say that this is not the answer for the question DamineBO asked. I also need to set the title but I don't use XML for layout. My application is completely dynamic, and everything is created from JSON, so my layouts are all in java code. If someone could help it'll be nice. Thanks in advance!

surveshoeb commented 7 years ago

Just change your XML <com.getbase.floatingactionbutton.FloatingActionsMenu android:id="@+id/add_req" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" app:fab_labelsPosition="left" app:fab_labelStyle="@color/black"/>

ali73 commented 6 years ago

It didn't work for me either. So I just set fab:fab_title="" in XML layout and all set_title()s worked fine.

mohammaddvi commented 5 years ago

Hi I have title problem for my fab, I try with settext() fab:fab_title and none of them work for me. Is there any stable solution?