Unexpected namespace prefix “app” found for tag RelativeLayout - Android?

后端 未结 7 2251
走了就别回头了
走了就别回头了 2021-02-13 04:46

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

Unexpected namespace prefix \"app\" found for tag RelativeLayout
         


        
相关标签:
7条回答
  • 2021-02-13 05:12

    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.

    0 讨论(0)
  • 2021-02-13 05:13

    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>
    
    0 讨论(0)
  • 2021-02-13 05:15

    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>
    
    0 讨论(0)
  • 2021-02-13 05:16

    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.

    0 讨论(0)
  • 2021-02-13 05:24
    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.

    0 讨论(0)
  • 2021-02-13 05:25

    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) :)

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