Appbar Overlaps with Other Elements

AppBar overlaps with other elements

This is happening because the MaterialUI App Bar defaults to position="fixed". This separates it from the standard DOM's layout to allow content to scroll beneath it, but as a result no space is made for it on the page.

You can get around this by wrapping all content below it in a div and specifying enough margin, or by changing the position property of <AppBar> so it's no longer "fixed". In your example, you could also just apply the styles to <Box> if that's the only content below the <AppBar>.

e.g.

import React from 'react';
import { AppBar, Typography, Box } from '@material-ui/core';

function App() {
return (
<div>
<AppBar>
<Typography variant='h3'>
AppBar
</Typography>
</AppBar>
<div style={{marginTop: 80}}>
<Box>
<Typography variant='h1' style={{ border: '1px solid black' }}>
Hello
</Typography>
</Box>
</div>
</div>
)
}

export default App;

Content beneath fixed AppBar

Your content is on screen, but covered up by the AppBar. You can use theme.mixins.toolbar to load information about the app bar height and shift your content accordingly:

const styles = theme => ({
// Load app bar information from the theme
toolbar: theme.mixins.toolbar,
});

And then create a div above your content to shift your content accordingly:

<Paper>
<div className={classes.toolbar} />
MyContent will be shifted downwards by the div above. If you remove
the div, your content will disappear under the app bar.
</Paper>

What's happening here is that theme.mixins.toolbar is loading information about the AppBar dimensions into your styles. Then, applying that information to the div sizes the div so that it's exactly the right height for shifting your content down the screen.

Here's a full working example:

import React from 'react';
import Paper from 'material-ui/Paper';
import Reboot from 'material-ui/Reboot';
import AppBar from 'material-ui/AppBar';
import Toolbar from 'material-ui/Toolbar';
import Typography from 'material-ui/Typography';
import { withStyles } from 'material-ui/styles';

const styles = (theme) => ({
toolbar: theme.mixins.toolbar,
});

const App = (props) => {
const { classes } = props;

return (
<div>
<Reboot />
<AppBar color="primary" position="fixed">
<Toolbar>
<Typography color="inherit" type="title">
My Title
</Typography>
</Toolbar>
</AppBar>
<Paper>
<div className={classes.toolbar} />
MyContent will be shifted downwards by the div above. If you remove
the div, your content will disappear under the app bar.
</Paper>
</div>
);
}

export default withStyles(styles)(App);

How to make Toolbar not overlap other content in Android?

try this in your layout:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity" >

<android.support.design.widget.AppBarLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:theme="@style/AppTheme.AppBarOverlay">

<android.support.v7.widget.Toolbar android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"/>

</android.support.design.widget.AppBarLayout>

<GridLayout
xmlns:android="http://schemas.android.com/apk/res/android"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_width="match_parent"
android:layout_height="match_parent"

android:useDefaultMargins="true"
android:alignmentMode="alignBounds"
android:columnOrderPreserved="false"

android:columnCount="4"
>

<TextView
android:text="MainTitle"
android:textSize="32dip"
android:layout_columnSpan="4"
android:layout_gravity="center_horizontal"
android:id="@+id/textView1"
/>

<TextView
android:text="You can configure email in just a few steps:"
android:textSize="16dip"

android:layout_columnSpan="4"
android:layout_gravity="left"
/>

<TextView
android:text="Email address:"

android:layout_gravity="right"
/>

<EditText
android:ems="10"
/>

<TextView
android:text="Password:"

android:layout_column="0"
android:layout_gravity="right"
/>

<EditText
android:ems="8"
/>

<Space
android:layout_row="4"
android:layout_column="0"
android:layout_columnSpan="3"
android:layout_gravity="fill"
/>

<Button
android:text="Next"
android:id="@+id/imageButton1"
android:layout_row="5"
android:layout_column="3"
/>
</GridLayout>

</android.support.design.widget.CoordinatorLayout>

Toolbar overlaps other content

Implement like this



<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/appbarlt">

<android.support.v7.widget.Toolbar
android:id="@+id/my_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary" />

</android.support.design.widget.AppBarLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_below="@+id/appbarlt"
app:layout_behavior="@string/appbar_scrolling_view_behavior">

<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>

</RelativeLayout>

How to stop overflow on Vuetify app-bar content

  • Replace cols="6" with cols="auto" on Get in touch button. If it's set to a numeric value, the width will be fixed. If it's not included, the col will expand to fill the row.
  • Remove v-spacer before LinkedIn (sibling inside v-row), add justify="end" to its parent v-row to align the content to the right.
  • Three nav buttons in the middle need to be wrapped in v-col (each). Move the v-for to a v-col (preferably a cols="4" so they don't shift rows as the page narrows). v-row always needs v-col as immediate child.
  • Also you have v-col and v-row as siblings, and the first v-col is not wrapped in the v-row.

Honestly you don't need ANY of those v-spacers. Just remove all of them and look into v-row justify properties. (space around, space between, etc.)

A trick to visualise content boxes is to add a style on all elements:

* {
outline: 1px solid lime;
}

Flutter: How to make a Card overlap the AppBar?

For one card it could be easily done with Stack widget

E.g.

import 'package:flutter/material.dart';

class Home extends StatefulWidget {
Home({Key key}) : super(key: key);

@override
HomeState createState() {
return new HomeState();
}
}

class HomeState extends State<Home> {
bool _hasCard;

@override
void initState() {
super.initState();
_hasCard = false;
}

@override
Widget build(BuildContext context) {
List<Widget> children = new List();

children.add(_buildBackground());
if (_hasCard) children.add(_buildCard());

return MaterialApp(
home: Stack(
children: children,
),
);
}

void _showCard() {
setState(() => _hasCard = true);
}

void _hideCard() {
setState(() => _hasCard = false);
}

Widget _buildCard() => new Container(
child: new Center(
child: new Container(
height: 700.0,
width: 200.0,
color: Colors.lightBlue,
child: new Center(
child: new Text("Card"),
),
),
),
);

Widget _buildBackground() => new Scaffold(
appBar: new AppBar(
title: new Text("AppBar"),
),
body: new Container(
child: _hasCard
? new FlatButton(
onPressed: _hideCard, child: new Text("Hide card"))
: new FlatButton(
onPressed: _showCard, child: new Text("Show card")),
),
);
}

void main() {
runApp(
new Home(),
);
}

If there are many cards, you can wrap them into ListView.



Related Topics



Leave a reply



Submit