19

I need to use BottomSheetBehavior with ScrollView but it says to me :

Unexpected namespace prefix "app" found for tag RelativeLayout

app:behavior_hideable="true"
app:behavior_peekHeight="80dp"

Here is my 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"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <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:id="@+id/ABLList"
            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">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:gravity="end"
                    android:orientation="horizontal">

                    <ImageButton
                        android:id="@+id/imbDetail"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="end|center_vertical"
                        android:layout_marginRight="10dp"
                        android:background="@null"
                        android:src="@drawable/ic_action_detail" />
                </LinearLayout>
            </android.support.v7.widget.Toolbar>

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

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recycler_OrderList"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/ABLList"
            android:scrollbars="vertical" />
    </RelativeLayout>

    <ScrollView
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <RelativeLayout
            android:id="@+id/layout_bottom_sheet_ListOrder"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="top"
            android:background="@color/color_bottom_sheet"
            android:gravity="top"
            app:behavior_hideable="true"
            app:behavior_peekHeight="80dp"
            app:layout_behavior="@string/string_bottom_sheet_behavior">

            <com.example.asheq.utils.TextViewJus
                android:id="@+id/txtAddress"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="@dimen/text_marginTop"
                android:gravity="right"
                android:maxLines="5"
                android:paddingLeft="@dimen/activity_vertical_margin"
                android:paddingRight="@dimen/activity_vertical_margin"
                android:textSize="@dimen/text_size"
                android:textStyle="bold" />

            <Button
                android:id="@+id/btnSReport"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/txtCTime"
                android:layout_marginTop="50dp"
                android:text="@string/btnReport" />

        </RelativeLayout>
    </ScrollView>

    <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/coordinatorOrder"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true" />
</android.support.design.widget.CoordinatorLayout>
Onik
  • 19,396
  • 14
  • 68
  • 91
  • 8
    For someone who get the error `Unexpected namespace prefix “app” found` for textView, you might need to change `TextView` to `android.support.v7.widget.AppCompatTextView` – 林果皞 Sep 27 '17 at 12:56
  • 2
    @林果皞 I think you can add that as an answer since seems like you're the only one that's really answering the answer. – Teng-pao Yu Jun 21 '18 at 05:50

7 Answers7

17

This issue is well known in while using data-binding in a layout.

Assume you want to use some data binding attribute with app: prefix then just adding xmlns:app... will not be enough. layout should be data binding layout wrapped with <layout tag.

Incorrect Approach:

e.g. I imported layout_toolbar_default.xml and using app:toolbarTitle to specify title.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    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"
    >

    <include
        layout="@layout/layout_toolbar_default"
        app:toolbarTitle="@{@string/app_name}"
        />

</LinearLayout>

This will show error Unexpected namespace prefix "app" found.

Solution:

Wrap your layout with <layout tag because you are using binding attribute.

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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        >

        <include
            layout="@layout/layout_toolbar_default"
            app:toolbarTitle="@{@string/app_name}"
            />

    </LinearLayout>
</layout>
Community
  • 1
  • 1
Khemraj Sharma
  • 57,232
  • 27
  • 203
  • 212
6

I had the same issue. Just take out your bottom-sheet layout into the separate file. And include it in the main layout via include tag.

Alireza Noorali
  • 3,129
  • 2
  • 33
  • 80
Valery Miller
  • 804
  • 1
  • 9
  • 13
6

Use of android.support.v7.widget.LinearLayoutCompat

<android.support.v7.widget.LinearLayoutCompat
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:behavior_hideable="true"
            app:behavior_peekHeight="80dp"
            app:layout_behavior="@string/string_bottom_sheet_behavior">

</android.support.v7.widget.LinearLayoutCompat>
5

For people using androidx, if you have child views from some androidx view, they should also be the androidx view to be able to recognize app namespace prefix. For example instead of:

<ImageView/> you should use <androidx.appcompat.widget.AppCompatImageView/>

This is not harmfull and it provides support for lower api version if you use some features that could not be supported (like tints for ImageView) :)

M. Wojcik
  • 2,301
  • 3
  • 23
  • 31
2

Try setting your xmlns namespace once in the parent layout if you are going to use it multiple times.

xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"

Writing this declaration once in your parent CoordinatorLayout will suffice.

Hint: When using multiple layouts and views, try to implement the <include/> attribute. It will make your code clean and easily readable.

AlphaQ
  • 656
  • 8
  • 18
1

For someone who gets the similar error Unexpected namespace prefix “app” found on textView, you might need to change TextView to android.support.v7.widget.AppCompatTextView.

林果皞
  • 7,539
  • 3
  • 55
  • 70
  • 1
    A documentation of AppCompatTextView says: `You should only need to manually use this class when writing custom views.` – ultraon Oct 08 '18 at 21:14
  • To whom downvote, you should know what's the meaning of `you might` (because of custom views), neither `you must` nor `you should`. – 林果皞 Feb 12 '20 at 16:52
0
xmlns:app="http://schemas.android.com/apk/res-auto"

This is set multiple times. Both in CoordinatorLayout and RelativeLayout. Remove the one in RelativeLayout. Declaring once in the file will suffice.

Alireza Noorali
  • 3,129
  • 2
  • 33
  • 80
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103