Android – how to set the icon to getbase floatingactionsmenu

I'm using com.getbase.floatingactionbutton.floatingactionsmenu for extensible fab. But I can't set the icon on the Fab menu. I tried to set the background with a paintable setting, but it didn't work properly. Thank you @ h_ 419_ 3@

@H_ 419_ 3@

         <FrameLayout
              android:id="@+id/frame_layout"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:background="@color/white_overlay">

         <com.getbase.floatingactionbutton.FloatingActionsMenu
             android:id="@+id/fab_menu"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_gravity="right|bottom"
             fab:fab_addButtonColorNormal="#C0007D"
             fab:fab_addButtonColorPressed="#C0007D"
             fab:fab_addButtonstrokeVisible="true"
             fab:fab_addButtonSize="normal"
             fab:fab_icon="@drawable/main_logo"
             fab:fab_labelStyle="@style/menu_labels_style"
             fab:fab_labelsPosition="left">



        <com.getbase.floatingactionbutton.FloatingActionButton
            android:id="@+id/locate_store"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            fab:fab_colorNormal="#C0007D"
            fab:fab_colorPressed="#C0007D"
            fab:fab_icon="@drawable/locate_store"
            fab:fab_size="mini"
            fab:fab_title="Locate Store" />

    </com.getbase.floatingactionbutton.FloatingActionsMenu>
</FrameLayout>

This is my java class code, @ H_ 419_ 3@

@H_ 419_ 3@

        final FloatingActionsMenu fabMenu = (FloatingActionsMenu)         v.findViewById(R.id.fab_menu);

        fabMenu.setOnFloatingActionsMenuUpdateListener(new FloatingActionsMenu.OnFloatingActionsMenuUpdateListener() {
        @Override
        public void onMenuExpanded() {
            frameLayout.getBackground().setAlpha(240);
            frameLayout.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    fabMenu.collapse();
                    return true;
                }
            });
        }

        @Override
        public void onMenuCollapsed() {
            frameLayout.getBackground().setAlpha(0);
            frameLayout.setOnTouchListener(null);
        }
    });

Solution: @ h_ 419_ 3@

I have come up with a possible solution. It is not universal, but it meets my needs. If you think this is not what you really need, I think it is better to continue. @ h_ 419_ 3@

Therefore, what I want to do is to derive the library futuresimple / Android floating action button. You need to add the library in the settings.gradle file and include ': Library'. Then delete it in the build.gradle file: @ H_ 419_ 3@

@H_ 419_ 3@

dependencies {
    compile 'com.getbase:floatingactionbutton:1.10.1'
}

I added a library from the project: @ h_ 419_ 3@

@H_ 419_ 3@

dependencies {
    compile project(':library')
}

Then, in the floatingactionsmenu class, I replace the private addfloatingactionbutton maddbutton; With private floatingactionbutton maddbutton If you check the addfloatingactionbutton class on line 59, an exception will be thrown when trying seticon on addfloatingactionbutton. I also added a method to update the icons colornormal and colorpressed: @ h_ 419_ 3@

@H_ 419_ 3@

public void setMenuButton(int myIcon, int myColorNormal, int myColorPressed) {
        mAddButton.setIcon(myIcon);
        mAddButtonColorNormal = myColorNormal;
        mAddButton.setColorNormalResId(mAddButtonColorNormal);
        mAddButtonColorPressed = myColorPressed;
        mAddButton.setColorPressed(mAddButtonColorPressed);
    }

The purpose of this method is to simply call all predefined methods on the floatingactionbutton class to update the button. @ H_ 419_ 3@

Next, get the code sample from the library in the layout file (. XML) and create a menu button: @ h_ 419_ 3@

@H_ 419_ 3@

<com.getbase.floatingactionbutton.FloatingActionsMenu
    android:id="@+id/multiple_actions"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentEnd="true"
    android:layout_alignParentRight="true"
    android:layout_marginBottom="16dp"
    android:layout_marginEnd="16dp"
    android:layout_marginRight="16dp"
    fab:fab_addButtonColorNormal="@color/white"
    fab:fab_addButtonColorPressed="@color/white_pressed"
    fab:fab_addButtonPlusIconColor="@color/half_black"
    fab:fab_labelStyle="@style/menu_labels_style">

Then, I choose to perform other operations in the *. Java file programmatically, but I can also define parts in the XML file, such as defining floating buttons. I will not describe in detail the information that can check the library sample directory. @ h_ 419_ 3@

Therefore, in my *. Java file, I called the *. XML file. @ H_ 419_ 3@

@H_ 419_ 3@

final FloatingActionsMenu menuMultipleActions = (FloatingActionsMenu) findViewById(R.id.multiple_actions);

You can then create any number of buttons you want to add, such as an example of a button created programmatically: @ h_ 419_ 3@

@H_ 419_ 3@

final FloatingActionButton actionA = new FloatingActionButton(getBaseContext());
        actionA.setTitle("Familie");
        actionA.setIcon(R.drawable.world_map);
        actionA.setSize(FloatingActionButton.SIZE_MINI);
        actionA.setColorNormalResId(R.color.red);
        actionA.setColorPressedResId(R.color.black_semi_transparent);
        actionA.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(MainMapView.this, "Action Description", Toast.LENGTH_SHORT).show();
                ((FloatingActionsMenu) findViewById(R.id.multiple_actions)).collapse();
                return;
            }
        });

This code example only creates buttons and adds the parameters you choose to define. Add any number of buttons as needed. @ h_ 419_ 3@

Then, the next step you need to do is to set the menu button. Code example: @ h_ 419_ 3@

@H_ 419_ 3@

menuMultipleActions.setMenuButton(R.drawable.icon2, R.color.blue, R.color.white_pressed);

Then, the last step is to add the previously created button. Code example: @ h_ 419_ 3@

@H_ 419_ 3@

menuMultipleActions.addButton(actionA);

I hope this will help you and solve your problem. According to my research, I found that others have created similar content using the same library, but now I can't find the link. If you search the Internet, you will find it. @ h_ 419_ 3@

At present, the color on the menu button is not updated correctly, but I am working on it. If I find a solution, I will update the answer here. I hope it will be helpful to you and have a good programming. @ h_ 419_ 3@

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>