Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add floating action button on the right-bottom side of the screen using material ui in react

I am trying to add FloatingActionButton on right bottom side of the screen. I am using this library http://www.material-ui.com/#/components/floating-action-button

import React, { Component } from "react";
import logo from "./logo.svg";
import "./App.css";

import AppBar from "material-ui/AppBar";
import FloatingActionButton from "material-ui/FloatingActionButton";
import MuiThemeProvider from "material-ui/styles/MuiThemeProvider";
import * as strings from "./Strings";
import styles from "./Styles";
import ContentAdd from "material-ui/svg-icons/content/add";

const AppBarTest = () =>
  <AppBar
    title={strings.app_name}
    iconClassNameRight="muidocs-icon-navigation-expand-more"
  />;

class App extends Component {
  render() {
    return (
      <MuiThemeProvider>
        <div>
          <AppBarTest />
          <FloatingActionButton style={styles.fab}>
            <ContentAdd />
          </FloatingActionButton>
        </div>

      </MuiThemeProvider>
    );
  }
}

export default App;

Styles.js

const style = {
    fab: {
        backgroundColor: '#000000'
    },
};

export default style;

Question 1

It is showing FloatingActionButton on top-left side, I want to make this on right-bottom side. What is the way to do this ?

Question 2

Why style is not applying on FloatingActionButton ?

enter image description here

like image 888
N Sharma Avatar asked Jun 12 '17 10:06

N Sharma


People also ask

Where do you put the floating action button?

The button should be placed in the bottom right corner of the screen. The recommended margin for the bottom is 16dp for phones and 24dp for tablets. In the example above, 16dp was used. The actual drawable size should be 24dp according to the Google design specs.

How do you make a floating action button?

Add the floating action button to your layoutThe size of the FAB, using the app:fabSize attribute or the setSize() method. The ripple color of the FAB, using the app:rippleColor attribute or the setRippleColor() method. The FAB icon, using the android:src attribute or the setImageDrawable() method.

What is a Floating Action Button (Fab)?

A floating action button (FAB) is a circular button that triggers the primary action in your app's UI. This page shows you how to add the FAB to your layout, customize some of its appearance, and respond to button taps.

How do I add a Floating Action Button in the bottom app?

Inside the Bottom app, the bar adds the bottom Navigation View and adds the menu items that we created in the last step. Add the Floating action button. Below is the code for the activity_main.xml file.

How to create a fab button in React Native?

Step 1: Open your Terminal and run the below command. It will install Expo CLI globally in your system. Step 2: Now, create a new React Native Project by running the below command. Step 3: You’ll be asked to choose a template. Select blank template. Step 4: Create a new file called FAB.js, This file is a custom component to create a FAB button.

How to create a floating navigation bar in Revit?

1 Change the root layout to Coordinator Layout 2 Add Bottom App bar. 3 Inside the Bottom app, the bar adds the bottom Navigation View and adds the menu items that we created in the last step. 4 Add the Floating action button.


1 Answers

Try this style:

const fabStyle = {
    right: 20,
    position: 'fixed'
};

and later u use margin, top... but don't use auto on position: fixed

like image 171
Gabriel Ferreira Avatar answered Sep 30 '22 17:09

Gabriel Ferreira