android - How to attach floating action menu to an already existing floating action menu? -
i trying make 1 of floating action buttons have multiple choices.
i have floating action button on side of screen.
when press 3 buttons pop out, first search button, second add button , third settings button. image 1
when press add button want have multiple buttons appear. image 2
i have looked on so , other sites android arsenal , youtube tutorials haven't found anything.
i have had shot @ writing code not working though builds no errors.
i using com.oguzdev:circularfloatingactionmenu:1.0.2
fab library if helps
here code:
mainactivity.java
public class mainactivity extends appcompatactivity implements view.onclicklistener{ private string[] navdraweritemtitles; private drawerlayout drawerlayout; private listview listview; toolbar toolbar; public static final string tag_add = "add"; private charsequence drawertitle; private charsequence title; android.support.v7.app.actionbardrawertoggle drawertoggle; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); window window = this.getwindow(); window.clearflags(windowmanager.layoutparams.flag_translucent_status); window.addflags(windowmanager.layoutparams.flag_draws_system_bar_backgrounds); window.setstatusbarcolor(contextcompat.getcolor(this, r.color.green)); title = drawertitle = gettitle(); navdraweritemtitles = getresources().getstringarray(r.array.nav_d_items); drawerlayout = (drawerlayout) findviewbyid(r.id.maindrawer); listview = (listview) findviewbyid(r.id.left_drawer); setuptoolbar(); // toolbox image imageview imageview = new imageview(this); imageview.setimageresource(r.drawable.hammers_green); // settings imageview settingsimagview = new imageview(this); settingsimagview.setimageresource(r.drawable.settings_green); // add button imageview addbutton = new imageview(this); addbutton.setimageresource(r.drawable.plus_green); // search button imageview searchimage = new imageview(this); searchimage.setimageresource(r.drawable.searches); // tag green imageview taggreen = new imageview(this); taggreen.setimageresource(r.drawable.tag_green_circle); // tag grey // imageview taggrey = new imageview(this); // taggrey.setimageresource(r.drawable.); // tag blue imageview tagblue = new imageview(this); tagblue.setimageresource(r.drawable.tag_blue_circle); // tag red // imageview tagred = new imageview(this); // tagred.setimageresource(r.drawable.); // layout parameters toolbox button floatingactionbutton.layoutparams layoutparams = new floatingactionbutton.layoutparams(300, 300); floatingactionbutton actionbutton = new floatingactionbutton.builder(this) .setcontentview(imageview) .setlayoutparams(layoutparams) .setposition(3) .build(); // subactionbuilder initial toolbox button click subactionbutton.builder toolboxbuttons = new subactionbutton.builder(this); subactionbutton settings = toolboxbuttons.setcontentview(settingsimagview).build(); subactionbutton add = toolboxbuttons.setcontentview(addbutton).build(); subactionbutton search = toolboxbuttons.setcontentview(searchimage).build(); // subactionbuilder add button click subactionbutton.builder addbuttonselections = new subactionbutton.builder(this); subactionbutton taggreenbutton = addbuttonselections.setcontentview(taggreen).build(); subactionbutton tagbluebutton = addbuttonselections.setcontentview(tagblue).build(); add.setonclicklistener(this); add.settag(tag_add); floatingactionmenu actionmenu = new floatingactionmenu.builder(this) .addsubactionview(settings, 200, 200) .addsubactionview(add, 400, 400) .addsubactionview(search, 200, 200) .setradius(400) .attachto(actionbutton) .build(); floatingactionmenu actionmenu1 = new floatingactionmenu.builder(this) .attachto(add) .addsubactionview(taggreenbutton, 150, 150) .addsubactionview(tagbluebutton, 150, 150) .setradius(200) .build(); drawerobjectdefiner[] drawerobjectdefiners = new drawerobjectdefiner[5]; drawerobjectdefiners[0] = new drawerobjectdefiner(r.drawable.house, "home"); drawerobjectdefiners[1] = new drawerobjectdefiner(r.drawable.import_export_green, "import/export"); drawerobjectdefiners[2] = new drawerobjectdefiner(r.drawable.photo_green, "pictures"); drawerobjectdefiners[3] = new drawerobjectdefiner(r.drawable.settings_icon, "settings"); drawerobjectdefiners[4] = new drawerobjectdefiner(r.drawable.qustion_mark_green, "help"); getsupportactionbar().setdisplayhomeasupenabled(false); getsupportactionbar().sethomebuttonenabled(true); drawercustomadapter adapter = new drawercustomadapter(this, r.layout.list_view_item_row, drawerobjectdefiners); listview.setadapter(adapter); listview.setonitemclicklistener(new draweritemclicklistener()); drawerlayout = (drawerlayout)findviewbyid(r.id.maindrawer); drawerlayout.adddrawerlistener(drawertoggle); setupdrawertoggle(); } @override public void onclick(view view) { if (view.gettag().equals(tag_add)){ actionmenu(); } }
activtiy_main.xml
<android.support.v4.widget.drawerlayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/maindrawer" android:layout_height="match_parent" android:layout_width="match_parent" android:background="@color/green"> <linearlayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <android.support.constraint.constraintlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/container_toolbar" android:orientation="vertical"> <include android:id="@+id/toolbar" layout="@layout/toolbar" app:layout_constraintleft_toleftof="parent" app:layout_constrainttop_totopof="parent" app:layout_constraintbottom_tobottomof="parent" app:layout_constraintright_torightof="parent" android:layout_height="0dp" android:layout_width="0dp" /> <imageview android:id="@+id/imageview2" android:layout_width="38dp" android:layout_height="31dp" app:srccompat="@drawable/menu_green" android:layout_marginleft="8dp" app:layout_constraintleft_toleftof="@+id/toolbar" android:layout_marginright="8dp" app:layout_constraintright_torightof="parent" app:layout_constrainttop_totopof="parent" android:layout_margintop="8dp" app:layout_constraintbottom_tobottomof="@+id/toolbar" android:layout_marginbottom="8dp" app:layout_constrainthorizontal_bias="0.0" app:layout_constraintvertical_bias="0.555" android:contentdescription="@string/menu" android:layout_marginstart="8dp" android:layout_marginend="8dp" /> </android.support.constraint.constraintlayout> <android.support.constraint.constraintlayout android:id="@+id/content_frame" android:layout_width="match_parent" android:layout_height="match_parent"> <listview android:layout_width="400dp" android:layout_height="596dp" android:layout_marginright="8dp" app:layout_constraintright_torightof="parent" android:layout_marginleft="8dp" app:layout_constraintleft_toleftof="parent" app:layout_constrainttop_totopof="parent" android:layout_margintop="8dp" app:layout_constrainthorizontal_bias="0.562" app:layout_constraintbottom_tobottomof="parent" android:layout_marginbottom="8dp" android:layout_marginstart="8dp" android:layout_marginend="8dp" app:layout_constraintvertical_bias="0.489" /> </android.support.constraint.constraintlayout> </linearlayout> <listview android:id="@+id/left_drawer" android:layout_width="240dp" android:layout_height="match_parent" android:layout_gravity="start" android:background="@color/white" android:choicemode="singlechoice" android:divider="@color/green" android:dividerheight="1dp"> </listview> </android.support.v4.widget.drawerlayout>
if need other info, please feel free ask.
so figured out.
all needed change buttons public vars , place floating action menu
method handled add button in add buttons onclicklistener
.
like this:
@override public void onclick(view view) { if (view.gettag().equals(tag_add)){ floatingactionmenu actionmenu1 = new floatingactionmenu.builder(this) .attachto(add) .addsubactionview(taggreenbutton, 150, 150) .addsubactionview(tagbluebutton, 150, 150) .setradius(200) .build(); } }
thanks every body!!
Comments
Post a Comment