0

I am implementing a list view in my app. I am trying to build my app for android 6.0 and chosen the theme "DarkActionBar". I am having this code right now in activity_main.xml.

<?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="com.mycompany.www.mynotes.MainActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        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"
            app:popupTheme="@style/AppTheme.PopupOverlay" />
    </android.support.design.widget.AppBarLayout>

    <ListView
        android:id="@+id/android:list"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    </ListView>

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

I have just added a listview (replacing a textview) in this code. Rest of code was already there when I created my project.

Right now I am adding some items randomly in the listview. Now the problem is, the top most item of list view gets behind the toolbar as shown in the image below. How to fix it? I want this listview to start below the toolbar.

enter image description here

Umair Jameel
  • 1,573
  • 3
  • 29
  • 54
  • What does this question have to do with Android Studio? Android Studio is an IDE for Android development. Your issue is IDE independent. – chRyNaN May 01 '16 at 19:02

1 Answers1

1

You have to add app:layout_behavior to your LiveView :

<ListView
        android:id="@+id/android:list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
Sharjeel
  • 15,588
  • 14
  • 58
  • 89
  • Thanks, it works. But can you please tell me, where is this appbar_scrolling_view_behavior come from. There is no resource like this in strings.xml. – Umair Jameel May 01 '16 at 19:17