Martin
Martin

Reputation: 506

Namespace is not Bound in Android Studio

If I create a new XML-file (using the default Android Studio "Create Linear Layout"), Studio makes a file with content:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

</LinearLayout>

If I (right)-click "Analyze... → Inspect Code" the result window throws 2 times: "Namespace is not bound" and references to line 3 and 7 (the LinearLayout-tags). Is it a bug in Studio?

Upvotes: 23

Views: 38678

Answers (5)

dicarlomagnus
dicarlomagnus

Reputation: 768

I just added in the xml on the root widget this line:

xmlns:tools="http://schemas.android.com/tools"

An example of this is:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
   android:layout_height="match_parent" 
  android:layout_width="match_parent">

then you can use attributes like:

tools:text="+52"

Upvotes: 3

live-love
live-love

Reputation: 52366

If you get the error:

Namespace 'tools' is not bound:

Example:

<activity
    android:name="com.google.android.gms.ads.AdActivity"
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
    tools:replace="android:theme"
    />

Add xmlns:tools="http://schemas.android.com/tools" at the top of the manifest (or activity).

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.mypackage"
    xmlns:tools="http://schemas.android.com/tools">

Upvotes: 33

Makvin
Makvin

Reputation: 3629

Add:

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

to yor manifest tag

Upvotes: 2

barbara
barbara

Reputation: 51

try this: in android studio 2.2.3 press F2 to jump between the warning then press Alt+Enter; this created the following reference: xmlns:app="http://schemas.android.com/apk/res-auto" and fixed the issue. Moreover, I checked my XML files and all have this encoding version: ?xml version="1.0" encoding="utf-8"?

Upvotes: 4

raystubbs
raystubbs

Reputation: 363

You must copy everything except the first line <?xml version="1.0" encoding="utf-8"?> from your xml file, create a new xml layout file and erase everything but the first line, then paste the copied content into the new file below the first line. Then you use the new layout file instead of the old one.

Note: This is just my interpretation of leo's answer, I don't know if it works or not and cannot test it because I don't have the same problem as you guys.

Upvotes: 5

Related Questions