Aapt error is incompatible with attribute background attr reference color

I can't run my app and some of the attributes are unrecognized, resources aren't supported as the app build results suggest.How do i fix all of the resource values? Can it be a problem from the

I can’t run my app and some of the attributes are unrecognized, resources aren’t supported as the app build results suggest.How do i fix all of the resource values? Can it be a problem from the dependencies? can the android studio read the dependecies and resource allocation.How is it related
to incompatablity issues of the android resources
Here is my xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:fab="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >
    <android.support.v7.widget.Toolbar
        android:id="@+id/toolBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:minHeight="?attr/actionBarSize"
        app:contentInsetLeft="0dp"
        app:contentInsetStart="16dp"
        android:background="@color/colorPrimary"
        />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/toolBar"
    android:id="@+id/add_reminder_layout_top"
    android:orientation="vertical"
    >
    <EditText
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:id="@+id/reminder_title"
        android:layout_marginLeft="32dp"
        android:layout_marginTop="10dp"
        android:hint="Name"
        android:textSize="20sp"
        android:minLines="1"
        android:background="@android:color/transparent"
        android:drawableLeft="@drawable/ic_person_black_24dp"
        android:drawablePadding="12dp"
        android:gravity="center|start"
        android:textColor="@android:color/background_dark"
        android:scrollHorizontally="false"
        android:textColorHint="@android:color/background_dark"
        android:inputType="textCapWords"
        android:layout_marginRight="16dp"
        />
    <EditText
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:id="@+id/phone_no"
        android:layout_marginLeft="32dp"
        android:hint="phone Number"
        android:layout_marginTop="15dp"
        android:layout_marginBottom="10dp"
        android:textSize="20sp"
        android:background="@android:color/transparent"
        android:drawableLeft="@drawable/ic_phone_black_24dp"
        android:drawablePadding="12dp"
        android:gravity="center|start"
        android:textColor="@android:color/background_dark"
        android:scrollHorizontally="false"
        android:textColorHint="@android:color/background_dark"
        android:inputType="phone"
        android:layout_marginRight="16dp"
        />
</LinearLayout>
<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_below="@+id/add_reminder_layout_top">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        <TextView
            android:layout_width="match_parent"
            android:layout_height="72dp"
            android:layout_marginTop="8dp"
            android:text="@string/details"
            android:id="@+id/details"
            android:textSize="15sp"
            android:gravity="center_vertical"
            android:layout_marginLeft="72dp"
            android:textColor="@android:color/primary_text_light"/>
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="72dp"
            android:clickable="true"
            android:onClick="setDate"
            android:id="@+id/date"
            android:background="@drawable/ic_launcher_foreground"
            >
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/date_icon"
                android:layout_alignParentLeft="true"
                android:layout_marginLeft="16dp"
                android:layout_marginRight="32dp"
                android:src="@drawable/ic_date"
                android:layout_centerVertical="true"/>
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:layout_toRightOf="@+id/date_icon">
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/date_text"
                    android:textSize="15dp"
                    android:text="@string/date"/>
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/set_date"
                    android:textSize="15dp"
                    />

            </LinearLayout>
        </RelativeLayout>
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="72dp"
            android:clickable="true"
            android:onClick="setTime"
            android:id="@+id/time"
            android:background="?android:attr/selectableItemBackground"> 


            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/time_icon"
                android:layout_alignParentLeft="true"
                android:layout_marginLeft="16dp"
                android:layout_marginRight="32dp"
                android:src="@drawable/ic_time"
                android:layout_centerVertical="true"/>
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:layout_toRightOf="@+id/time_icon">
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/time_text"
                    android:textSize="15dp"
                    android:text="@string/time"/>
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/set_time"
                    android:textSize="15dp"
                    />

            </LinearLayout>
        </RelativeLayout>
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="72dp"
            android:id="@+id/repeat">

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/repeat_icon"
                android:layout_alignParentLeft="true"
                android:layout_marginLeft="16dp"
                android:layout_marginRight="32dp"
                android:src="@drawable/ic_repeat"
                android:layout_centerVertical="true"/>
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:id="@+id/repeat_ll"
                android:layout_toRightOf="@+id/repeat_icon">
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/repeat_text"
                    android:textSize="15dp"
                    android:text="@string/repeat"/>
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/set_repeat"
                    android:textSize="15dp"
                    />
            </LinearLayout>
            <Switch
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/repeat_switch"
                android:layout_centerVertical="true"
                android:layout_alignParentRight="true"
                android:layout_marginRight="16dp"
                android:layout_marginLeft="8dp"
                android:onClick="onSwitchRepeat"
                android:checked="true"
                android:textOn="On"
                android:textOff="Off"/>
        </RelativeLayout>
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="72dp"
            android:clickable="true"
            android:onClick="setRepeatNo"
            android:id="@+id/repeat_no"
            android:background=""
            >
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/repeat_no_icon"
                android:layout_alignParentLeft="true"
                android:layout_marginLeft="16dp"
                android:layout_marginRight="32dp"
                android:src="@drawable/ic_repeat_no"
                android:layout_centerVertical="true"/>
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:layout_toRightOf="@+id/repeat_no_icon">
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/repeat_no_text"
                    android:textSize="15dp"
                    android:text="@string/repetition_interval"/>
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/set_repeat_no"
                    android:textSize="15dp"
                    />

            </LinearLayout>
        </RelativeLayout>
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="72dp"
            android:clickable="true"
            android:onClick="selectRepeatType"
            android:id="@+id/repeat_type"
            android:background="@mipmap/ic_launcher"
            >
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/repeat_type_icon"
                android:layout_alignParentLeft="true"
                android:layout_marginLeft="16dp"
                android:layout_marginRight="32dp"
                android:src="@drawable/ic_repeat_no"
                android:layout_centerVertical="true"/>
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:layout_toRightOf="@+id/repeat_type_icon">
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/repeat_type_text"
                    android:textSize="15dp"
                    android:text="@string/type_of_repetitions"/>
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/set_repeat_type"
                    android:textSize="15dp"
                    />

            </LinearLayout>
        </RelativeLayout>
    </LinearLayout>
</ScrollView>

<com.getbase.floatingactionbutton.FloatingActionButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/starred1"
    android:clickable="true"
    android:onClick="selectFab1"
    fab:fab_icon="@drawable/notification_off"
    fab:fab_colorNormal="@color/colorAccent"
    fab:fab_colorPressed="@color/colorPrimary"
    app:fab_size="mini"
    android:layout_alignParentRight="true"
    android:layout_marginTop="170dp"
    android:layout_centerHorizontal="true"
    android:layout_marginLeft="5dp"/>
<com.getbase.floatingactionbutton.FloatingActionButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/starred2"
    android:clickable="true"
    android:onClick="selectFab2"
    fab:fab_icon="@drawable/notification_on"
    fab:fab_colorNormal="@color/colorAccent"
    fab:fab_colorPressed="@color/colorPrimary"
    app:fab_size="mini"
    android:layout_alignParentRight="true"
    android:layout_marginTop="170dp"
    android:layout_centerHorizontal="true"
    android:layout_marginLeft="5dp"/>

<CheckBox
    android:id="@+id/checkBox_completed"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/add_reminder_layout_top"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_marginBottom="11dp"
    android:layout_marginLeft="48dp"
    android:layout_marginStart="48dp"
    android:text="Completed" />

<CheckBox
    android:id="@+id/checkBox_failed"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/checkBox_completed"
    android:layout_alignBottom="@+id/checkBox_completed"
    android:layout_alignParentEnd="true"
    android:layout_alignParentRight="true"
    android:layout_marginEnd="37dp"
    android:layout_marginRight="37dp"
    android:text="Failed" />

>

And here is my error

Information:Gradle tasks [:app:generateReleaseSources, :app:mockableAndroidJar]
C:UsersghjskAndroidStudioProjectsNavDrawerappsrcmainreslayoutactivity_add_reminder.xml
Error:error: '' is incompatible with attribute android:background (attr) reference|color.
Error:'' is incompatible with attribute android:background (attr) reference|color.
Error:failed linking file resources.
Error:java.util.concurrent.ExecutionException: java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:Execution failed for task ':app:processReleaseResources'.
> Failed to execute aapt
Information:BUILD FAILED in 18s
Information:7 errors
Information:0 warnings
Information:See complete output in console

I am new to Android dev and am working on my first app. I have been running into trouble trying to get an image view set up with my own image (stock photos on studio are working fine), and am getting the following error:

AAPT: error: ‘/home/joshua/AndroidStudioProjects/WSC/app/src/main/res/mipmap-xxxhdpi/wsc_foreground.png’ is incompatible with attribute src (attr) reference|color.

I have researched around to even try to understand what this error is saying, and I think it is having trouble linking some file/resource?

I uploaded a .jpg using the add image asset option in android studio. I added a color background to the image, which was a hex number I selected.

I am not getting any errors or warnings until I build, at which point the build fails.

**Can someone please explain:

  1. What this error means.
  2. How to troubleshoot this.
  3. Where my mistake lies.**

I have attached the (hopefully sufficiently) relevant XML code.

Here is the image view inside of my fragment_first.xml, which is inside layout:

<ImageView
        android:id="@+id/wsc_image"
        android:layout_width="930dp"
        android:layout_height="585dp"
        android:layout_marginTop="44dp"
        android:contentDescription="@string/wsc_image_description"
        android:src="/home/joshua/AndroidStudioProjects/WSC/app/src/main/res/mipmap-xxxhdpi/wsc_foreground.png"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="@+id/textview_first"
        app:layout_constraintStart_toStartOf="@+id/textview_first"
        app:layout_constraintTop_toBottomOf="@+id/textview_first"
        app:layout_constraintVertical_bias="0.0" />

I don’t have an XML for the wsc_foreground.png, but do have a wsc.xml. I tried adding the full path in the wsc.xml for wsc_foreground.png, but this did not change anything.

<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
    <background android:drawable="@color/wsc_background"/>
    <foreground android:drawable="/home/joshua/AndroidStudioProjects/WSC/app/src/main/res/mipmap-xxxhdpi/wsc_foreground.png"/>
</adaptive-icon>

My apologies if this is a dumb question and/or not clear. Please let me know in the comments if I need to clarify any of this.

Thanks!

Устранение неполадок: AAPT: ошибка: несовместимо с атрибутом src (attr) reference | color

Я новичок в разработке Android и работаю над своим первым приложением. У меня возникли проблемы с попыткой настроить просмотр изображения с помощью моего собственного изображения (стоковые фотографии в студии работают нормально), и я получаю следующую ошибку:

AAPT: ошибка: ‘/home/joshua/AndroidStudioProjects/WSC/app/src/main/res/mipmap-xxxhdpi/wsc_foreground.png’ несовместимо с атрибутом src (attr) reference | color.

Я исследовал все вокруг, чтобы даже попытаться понять, о чем говорит эта ошибка, и я думаю, что у него проблемы с связыванием какого-либо файла / ресурса?

Я загрузил .jpg с помощью опции добавления изображения в студию Android. Я добавил к изображению цветной фон — выбранное мной шестнадцатеричное число.

Я не получаю никаких ошибок или предупреждений, пока не начну сборку, после чего сборка завершится ошибкой.

** Может кто-нибудь объяснить:

  1. Что означает эта ошибка.
  2. Как это исправить.
  3. В чем моя ошибка. **

Я приложил (надеюсь, достаточно) соответствующий XML-код.

Вот изображение внутри моего файла fragment_first.xml, который находится внутри макета:

У меня нет XML для wsc_foreground.png, но есть wsc.xml. Я попытался добавить полный путь к wsc_foreground.png в wsc.xml, но это ничего не изменило.

Приношу свои извинения, если это глупый вопрос и / или непонятный. Пожалуйста, дайте мне знать в комментариях, если мне нужно что-то прояснить.

Источник

I am new to Android dev and am working on my first app. I have been running into trouble trying to get an image view set up with my own image (stock photos on studio are working fine), and am getting the following error:

AAPT: error: ‘/home/joshua/AndroidStudioProjects/WSC/app/src/main/res/mipmap-xxxhdpi/wsc_foreground.png’ is incompatible with attribute src (attr) reference|color.

I have researched around to even try to understand what this error is saying, and I think it is having trouble linking some file/resource?

I uploaded a .jpg using the add image asset option in android studio. I added a color background to the image, which was a hex number I selected.

I am not getting any errors or warnings until I build, at which point the build fails.

**Can someone please explain:

  1. What this error means.
  2. How to troubleshoot this.
  3. Where my mistake lies.**

I have attached the (hopefully sufficiently) relevant XML code.

Here is the image view inside of my fragment_first.xml, which is inside layout:

<ImageView
        android:id="@+id/wsc_image"
        android:layout_width="930dp"
        android:layout_height="585dp"
        android:layout_marginTop="44dp"
        android:contentDescription="@string/wsc_image_description"
        android:src="/home/joshua/AndroidStudioProjects/WSC/app/src/main/res/mipmap-xxxhdpi/wsc_foreground.png"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="@+id/textview_first"
        app:layout_constraintStart_toStartOf="@+id/textview_first"
        app:layout_constraintTop_toBottomOf="@+id/textview_first"
        app:layout_constraintVertical_bias="0.0" />

I don’t have an XML for the wsc_foreground.png, but do have a wsc.xml. I tried adding the full path in the wsc.xml for wsc_foreground.png, but this did not change anything.

<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
    <background android:drawable="@color/wsc_background"/>
    <foreground android:drawable="/home/joshua/AndroidStudioProjects/WSC/app/src/main/res/mipmap-xxxhdpi/wsc_foreground.png"/>
</adaptive-icon>

My apologies if this is a dumb question and/or not clear. Please let me know in the comments if I need to clarify any of this.

Thanks!

Я добавил BottomNavigationView в моем приложении, как.

MAIN.XML

<com.google.android.material.bottomnavigation.BottomNavigationView
    android:layout_width="match_parent"
    android:layout_height="56dp"
    app:itemBackground="@drawable/nav_bgcolor"
    app:itemIconSize="50dp"
    app:itemIconTint="@color/nav_item_colors"
    app:itemTextColor="@color/nav_item_colors"
    app:labelVisibilityMode="unlabeled"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:menu="@menu/nav_items">
</com.google.android.material.bottomnavigation.BottomNavigationView>

< Сильный > меню / nav_items.xml

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

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

    <item
        android:id="@+id/nav_home"
        android:icon="@drawable/home_white"
        android:title="@string/nav_home" />
    <item
        android:id="@+id/nav_market"
        android:icon="@drawable/market_white"
        android:title="@string/nav_market" />
    <item
        android:id="@+id/nav_news"
        android:icon="@drawable/news_white"
        android:title="@string/nav_news" />
    <item
        android:id="@+id/nav_account"
        android:icon="@drawable/account_white"
        android:title="@string/nav_account" />
</menu>

< Сильный > вытяжке / nav_bgcolor.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="#FF9800" android:state_checked="true" />
    <item android:drawable="#FFFFFF" android:state_checked="false" />
</selector>

< Сильный > цвет / nav_item_colors.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:color="#FFFFFF" android:state_checked="true"/>
    <item android:color="#727272"/>
</selector>

Это превью в андроид студии

https://drive.google.com/file/d/1yICxFcTbSxYpILDtxg75Z4x-2Y1UaPM_/view?usp=sharing

Это на самом деле отображает дизайн, который я хочу, чтобы это произошло.

Нет ошибки или чего-то еще, но когда я запускаю приложение, в drawable / nav_bgcolor.xml возникают ошибки

C:Users[PCNAME]AndroidStudioProjects[APPNAME]appsrcmainresdrawablenav_bgcolor.xml:3: AAPT: error: '#FF9800' is incompatible with attribute drawable (attr) reference.
C:Users[PCNAME]AndroidStudioProjects[APPNAME]appsrcmainresdrawablenav_bgcolor.xml:4: AAPT: error: '#ffffff' is incompatible with attribute drawable (attr) reference.

Ошибка произошла после того, как я добавил app: itemBackground = «@ drawable / nav_bgcolor» в main.xml

Я искал в интернете, но мне не повезло в поиске решения.

2 ответа

Лучший ответ

В вашем селекторе вы используете

<selector>
    <item android:drawable="#FF9800" android:state_checked="true" />

Вы не можете использовать цвет (#FF9800), где вы должны определить android:drawable.

Использовать

<menu>
    <item
        android:id="@+id/nav_home"
        android:icon="@drawable/icon_add"
        android:title="@string/nav_home" />
    ...
</menu>

Где icon_add — простая отрисовка.
И в вашем BottomNavigationView:

<com.google.android.material.bottomnavigation.BottomNavigationView
     app:itemIconTint="@color/nav_item_colors"
     ../>


0

Gabriele Mariotti
23 Окт 2019 в 22:47

заменить android: рисовать на android: цвет в drawable / nav_bgcolor.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:color="#FF9800" android:state_checked="true" />
    <item android:color="#FFFFFF" android:state_checked="false" />
</selector>


0

Hardik Bhalala
23 Окт 2019 в 13:23

У меня возникает эта проблема, когда я пытаюсь изменить свой android:background в XML-файле моей активности.

Information:Gradle tasks [:app:assembleDebug]
C:UsersValentinAndroidStudioProjectsCedarRestaurants4CedarRestaurants3appsrcmainreslayoutactivity_dynamic_view_ordering.xml
Error:error: 'drawable/delete' is incompatible with attribute android:background (attr) reference|color.
Error:'drawable/delete' is incompatible with attribute android:background (attr) reference|color.
Error:failed linking file resources.
Error:java.util.concurrent.ExecutionException: java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:Execution failed for task ':app:processDebugResources'.
> Failed to execute aapt
Information:BUILD FAILED in 4s
Information:7 errors
Information:0 warnings
Information:See complete output in console

XML-файл моей активности:

<?xml version = "1.0" encoding = "utf-8"?>
<RelativeLayout
android:layout_width = "match_parent"
android:layout_height = "match_parent"
xmlns:android = "http://schemas.android.com/apk/res/android">

<LinearLayout xmlns:android = "http://schemas.android.com/apk/res/android"
    android:id = "@+id/parent_linear_layout"
    android:layout_width = "match_parent"
    android:layout_height = "match_parent"
    android:layout_margin = "5dp"
    android:orientation = "vertical" >
    <LinearLayout xmlns:android = "http://schemas.android.com/apk/res/android"
        android:layout_width = "match_parent"
        android:layout_height = "50dp"
        android:orientation = "horizontal" >
        <EditText
            android:id = "@+id/number_edit_text"
            android:layout_width = "0dp"
            android:layout_height = "match_parent"
            android:layout_weight = "5" />

        <Button
            android:id = "@+id/delete_button"
            android:layout_width = "0dp"
            android:layout_height = "wrap_content"
            android:layout_weight = "1"
            android:background = "drawable/delete.png"
            android:onClick = "onDelete" />
    </LinearLayout>
    <Button
        android:id = "@+id/add_field_button"
        android:layout_width = "100dp"
        android:layout_height = "wrap_content"
        android:layout_marginBottom = "5dp"
        android:layout_marginLeft = "5dp"
        android:layout_marginRight = "5dp"
        android:background = "#555"
        android:layout_gravity = "center"
        android:onClick = "onAddField"
        android:textColor = "#FFF"
        android:text = "New"
        android:paddingLeft = "5dp"/>
</LinearLayout>

<Button
    android:id = "@+id/placeOrderButton"
    android:layout_width = "wrap_content"
    android:layout_height = "wrap_content"
    android:layout_alignBottom = "@+id/parent_linear_layout"
    android:layout_centerHorizontal = "true"
    android:layout_marginBottom = "250sp"
    android:text = "@string/place_order"
    android:textSize = "32sp" />


</RelativeLayout>

Я скопировал файл макета активности и активность из учебного проекта и пытаюсь изменить ресурсы изображения на что-то более современное.

Я уже убедился, что мой delete.png внутри /src/main/res/drawable, и уже пытался избавиться от .png в конце, но безуспешно. Любая помощь приветствуется.

Я пытаюсь изменить атрибут фона TextView на основе метода, который возвращает логическое значение.
Итак, вот как выглядит мой TextView

<data>
    <variable
        name = "model"
        type = "fit.cure.meetingdisplay.MeetingModel" />
</data>
.....
<TextView
    android:layout_width = "match_parent"
    android:layout_height = "wrap_content"
    android:layout_gravity = "center"
    android:background = "@{model.isAvailable() ? @color/colorAvailable : @color/colorUnavailable, default=@color/colorAvailable"
    android:gravity = "center"
    android:text = "@{model.getAvailabilityText(), default=Available}"
    android:textAllCaps = "true"
    android:textAppearance = "@android:style/TextAppearance.Holo.Large.Inverse" />

Модель выглядит следующим образом —

public class MeetingModel {
    private boolean isAvailable = false;

    public boolean isAvailable() {
        return isAvailable;
    }

    public void setAvailable(boolean available) {
        isAvailable = available;
    }

    public String getAvailabilityText() {
        if (isAvailable) {
            return "available";
        }
        return "unavailable";
    }
}

Но я получаю эту ошибку при создании проекта —

error: '@{model.isAvailable() ? @color/colorAvailable : @color/colorUnavailable, default=@color/colorAvailable' is incompatible with attribute android:background (attr) reference|color.
Message{kind=ERROR, text=error: '@{model.isAvailable() ? @color/colorAvailable : @color/colorUnavailable, default=@color/colorAvailable' is incompatible with attribute android:background (attr) reference|color., sources=[/Volumes/Projects/Work/Clients/CureFit/MeetingDisplay/app/src/main/res/layout/activity_main.xml:55], original message=, tool name=Optional.of(AAPT)}

Я использую @color/colorAvailable, так как было упомянуто здесь, что его можно использовать. Я также пробовал подход с возможностью рисования, используя следующее для значения фона:

"@{model.isAvailable() ? @drawable/drawable_available : @drawable/drawable_unavailable, default=@drawable/drawable_available"

Чертежи определены в файле colors.xml следующим образом:

<drawable name = "drawable_available">@color/colorAvailable</drawable>
<drawable name = "drawable_unavailable">@color/colorUnavailable</drawable>

По-прежнему возникает та же ошибка. Как ни странно, значение по умолчанию работает в обоих случаях.

Итак, что-то я здесь делаю не так, или вообще невозможно привязать атрибут background (хотя я не думаю, что это невозможно).

noob, 18 апреля 2018 г., 09:13

2

1 138

1

Понравилась статья? Поделить с друзьями:
  • A start job is running for dev disk by как исправить
  • A software problem has caused 3ds max to close unexpectedly как исправить 2017
  • A software execution error occurred inside the mesher ansys
  • A socket error occurred during the upload test
  • A socket error occurred during the download test a firewall could be blocking