将drawable设置为背景,以查看返回未找到的drawable

问题描述 投票:-1回答:2

enter image description herei在我之前的观点中总是添加drawable作为背景。但最近当我添加一个drawable作为背景到任何视图,如LinearLayout,视图,TextView我得到此错误

 error: resource drawable/rectangle_white (aka merchant.com.our.nextlounge:drawable/rectangle_white) not found.
Message{kind=ERROR, text=error: resource drawable/rectangle_white (aka merchant.com.our.nextlounge:drawable/rectangle_white) not found., sources=[C:\Users\USER\Documents\Exolve Project\NextLounge\app\src\main\res\layout\activity_dash_auth.xml:45], original message=, tool name=Optional.of(AAPT)}

我已经刷新,清洁,构建但它不起作用。唯一可行的方法是,如果我添加多个可绘制的API文件夹,如drawable-v21,drawable-v22,drawable-v23

它的工作原理。请问我该如何解决这个问题。

<?xml version="1.0" encoding="utf-8"?>
 <android.support.constraint.ConstraintLayout 
  xmlns:android="http://schemas.android.com/apk/res/android"
  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=".activity.DashAuthActivity">
<include layout="@layout/background_auth"/>

  <include layout="@layout/logo"
   android:id="@+id/logo"
   android:layout_height="wrap_content"
   android:layout_width="wrap_content"
   app:layout_constraintLeft_toLeftOf="parent"
   app:layout_constraintRight_toRightOf="parent"
   app:layout_constraintTop_toTopOf="parent"/>
<TextView
    android:id="@+id/text"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:text="@string/intro_text"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toBottomOf="@id/logo"
    app:layout_constraintBottom_toBottomOf="@id/linearLine"
    android:layout_margin="20sp"
    app:layout_constraintVertical_bias="0.0"
    android:padding="8dp"
    android:textAlignment="center"
    android:textColor="@color/white"/>
<LinearLayout
    android:id="@+id/linearLine"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:weightSum="4"
    android:padding="4dp"
    android:layout_margin="24dp"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintVertical_bias="0.96"
    app:layout_constraintBottom_toTopOf="@+id/linearButton"
    android:layout_marginBottom="20sp">
    <View
        android:layout_width="0dp"
        android:layout_height="6dp"
        android:background="@drawable/rectangle_white"
        android:layout_weight="2.5"/>
    <View
        android:layout_width="0dp"
        android:layout_height="1dp"
        android:layout_weight="0.3"/>
    <View
    android:layout_width="0dp"
    android:layout_height="6dp"
    android:background="@drawable/rectangle_white_line"
    android:layout_weight="1.2"/>
</LinearLayout>
 <LinearLayout
android:id="@+id/linearButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="4"
android:padding="4dp"
android:layout_margin="20dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent">

   <Button
    android:id="@+id/buttonSignIn"
    android:layout_width="0dp"
    android:layout_height="48dp"
    android:layout_weight="2"
    android:layout_marginRight="4dp"
    android:layout_marginEnd="4dp"
    android:text="@string/sign_in"
    android:textColor="@color/black"
    android:textAllCaps="false"
    android:textSize="18sp"
    android:background="@color/white"/>
    <Button
    android:id="@+id/buttonSignUp"
    android:layout_width="0dp"
    android:layout_height="48dp"
    android:layout_weight="2"
    android:layout_marginLeft="4dp"
    android:layout_marginStart="4dp"
    android:text="@string/sign_up"
    android:textAllCaps="false"
    android:textSize="18sp"
    android:textColor="@color/white"
    android:background="@color/orange"/>

下面是rectangle_white.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
  android:shape="rectangle">
  <stroke android:color="#fff"
     android:width="2dp"/>

</shape>

Error message during Build

android xml kotlin
2个回答
0
投票

在运行时,将被选中的drawable是最适合该设备的android版本的drawable, 除非只有1个drawable文件夹,在这种情况下只有1个drawable。 自从drawable-v21drawable-v22drawable-v23等工作的其他版本drawables, 但主要drawable中的drawable不起作用,这意味着后者drawable是问题。 我建议您检查它是否存在xml结构中的错误,或者是否可以重新创建它。


0
投票

嗨谢谢你们所有有用的回应。我所要做的就是删除包含所有内容的整个drawable文件夹,然后我创建了一个新的drawable文件夹并重新创建了所有文件。一旦我这样做我运行它,它适用于所有Android设备。所以我不必为不同的API版本创建特定的文件夹

© www.soinside.com 2019 - 2024. All rights reserved.