Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Add floating action button
- Gradle
- ============
- dependencies
- {
- implementation 'io.github.yavski:fab-speed-dial:1.0.6'
- }
- =================================================================================================================
- Create new file in res
- - File Name = "main_menu"
- - Resourse Type = "menu"
- -----------------------------
- <?xml version="1.0" encoding="utf-8"?>
- <menu xmlns:android="http://schemas.android.com/apk/res/android">
- <item android:id="@+id/phone_button"
- android:icon="@drawable/call"
- android:title="Call"
- />
- <item android:id="@+id/msg_button"
- android:icon="@drawable/chat"
- android:title="Send SMS"
- />
- </menu>
- ====================================================================================================================
- Create 2 darawable files
- ---------------------------
- Type Vector Asset
- 1. Chose "phone" icon and make file with name = "call"
- 2. Chose "mail outline" icon and make file with name "chat"
- =====================================================================================================================
- Write in activity.xml
- --------------------------
- <FrameLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent">
- <io.github.yavski.fabspeeddial.FabSpeedDial
- android:id="@+id/fabSpeedDial"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="bottom|end"
- app:fabGravity="bottom_end"
- app:fabMenu="@menu/main_menu"
- app:miniFabBackgroundTint="#ffffff"
- app:miniFabDrawableTint="?attr/colorPrimaryDark"
- app:miniFabTitleTextColor="?attr/colorPrimaryDark"
- />
- </FrameLayout>
- ====================================================================================================================
- Write inside MainActivity.java
- -------------------------------
- FabSpeedDial fabSpeedDial = (FabSpeedDial)findViewById(R.id.fabSpeedDial);
- fabSpeedDial.setMenuListener(new FabSpeedDial.MenuListener() {
- @Override
- public boolean onPrepareMenu(NavigationMenu navigationMenu) {
- return true;
- }
- @Override
- public boolean onMenuItemSelected(MenuItem menuItem) {
- switch (menuItem.getItemId())
- {
- case R.id.phone_button:
- {
- }
- break;
- case R.id.msg_button:
- {
- }
- break;
- }
- return true;
- }
- @Override
- public void onMenuClosed() {
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement