命名空间“ app”不绑定,在 Android Studio 中使用来自 Maven 的外部库

每当我尝试为外部 libs UI 元素指定属性时,我都不会绑定 Namespace‘ app’。

        <LinearLayout
android:id="@+id/card_database"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:onClick="dbclicked"
android:orientation="horizontal"
android:background="#ffff7f31"
>


<ImageView
android:id="@+id/img_database"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/db"
/>


<TextView
android:id="@+id/txt_database"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:paddingStart="15dp"
android:text="@string/db"
android:textColor="#ffffff"
android:textSize="20sp"
android:autoText="false" />
</LinearLayout>
</com.balysv.materialripple.MaterialRippleLayout>

在 build.gradle 中使用了编译‘ com.balysv: Materials-riple: 1.0.0’,我正在运行带有更新的最新版本的 Android Studio。

59712 次浏览

Add

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

to your root element

Simply select the error (touch the error by mouse) and press. "ALT+ENTER" it will automatically solve the error.

So I have opened like 10 questions just like yours trying to solve this issue, but all the solutions never worked for me. Am going to post this to every other question similar to this one, just in case someone else get stuck in my position.

What worked for me: Open Tools> SDK manager then press edit SDK location. Now note the location, open it using windows explorer, copy the SDK folder to another location eg Desktop, Documents. Once done go back to edit SDK location then choose a new location where you pasted the SDK folder, press next then wait. It should be fixed.

Add xmlns:app="http://schemas.android.com/apk/res-auto" to root like this:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:orderInCategory="1"
app:showAsAction = "ifRoom"
/>


</menu>