首页 > 解决方案 > 如果存储库的属性不起作用,如何解决?

问题描述

我在我的活动中使用带有 MaterialAnimatedSwitch 的地图片段。还没有 Java 代码。

在 XML 中,当我尝试从 MaterialAnimatedSwitch 添加属性时,首先它们不会在键入前几个字母时显示,然后当我简单地编写属性时,如https://github.com/glomadrian/material-animated-switch所示 应用程序崩溃。

我知道这与命名空间的冲突有关

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

两者都涉及。

我尝试了不同的可能性,例如在根布局中定义一个,在根布局中定义一个,在地图片段中定义一个,等等。

但结果是一样的。该应用程序因日志而崩溃

java.lang.RuntimeException: 
Unable to start activity ComponentInfo
{com.example.dell.vehicledrivers/com.example.dell.vehicledrivers.MapsActivity}: 
android.view.InflateException: 
Binary XML file line #19: Binary XML file line #19: 
Error inflating class com.github.glomadrian.materialanimatedswitch.MaterialAnimatedSwitch

我知道我犯了一个非常基本的错误,但我找不到任何提示。怎么可能解决?

编辑

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    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"
    tools:context=".MapsActivity" >

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/map"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentStart="true"
    android:layout_alignParentTop="true"
    tools:context=".MapsActivity" />

<com.github.glomadrian.materialanimatedswitch.MaterialAnimatedSwitch
    android:id="@+id/driverSwitch"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentStart="true"
    android:layout_marginBottom="45dp"
    android:layout_marginStart="45dp"
    app:base_release_color="@android:color/darker_gray"
    app:base_press_color="@android:color/white"
    app:ball_release_color="@android:color/darker_gray"
    app:ball_press_color="@android:color/white"
    app:icon_release="@drawable/ic_location_off_black_24dp"
    app:icon_press="@drawable/ic_location_on_black_24dp"
    />

</RelativeLayout>

标签: androidattributesxml-namespaces

解决方案


推荐阅读