How to make Toolbar not overlap other content in Android?

前端 未结 6 1565
北恋
北恋 2020-12-29 04:51

I am trying to develop an activity with a toolbar (the example is more or less taken from a tutorial), but the Toolbar always overlaps part of the other content. Here is a

相关标签:
6条回答
  • 2020-12-29 05:20

    Just a simple change did the trick.

    My Previous code:

    activity_device_scan.xml

        <include layout="@layout/content_device_scan"/>
    

    New

    activity_device_scan.xml:

        <include layout="@layout/content_device_scan"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
    
    0 讨论(0)
  • 2020-12-29 05:21

    Replace your <include layout="@layout/content_main"/> with this:

       <include layout="@layout/content_main" 
          android:layout_width="match_parent" 
          android:layout_height="match_parent"
          app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
    
    0 讨论(0)
  • 2020-12-29 05:25

    if

    "@string/appbar_scrolling_view_behavior"
    

    doesn't work, then try to call it directly, like

    app:layout_behavior="android.support.design.widget.AppBarLayout$ScrollingViewBehavior"
    
    0 讨论(0)
  • 2020-12-29 05:27

    Add this to the view below the toolbar

    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    
    0 讨论(0)
  • 2020-12-29 05:34

    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>
    
    0 讨论(0)
  • 2020-12-29 05:39

    I changed the CoordinatorLayout for activity_main to a vertical linear layout and it worked. I had Android Studio convert the view type for me and at first it broke my inclusion of the content_main. I restored the include callout as part of my conversion.

    0 讨论(0)
提交回复
热议问题