I have some drawable resources that are used only in a single xml layout. I would like to insert them into the specific xml layout (inline) so i could have a better organization of my files and a less overloaded drawable folder
i found this topic: https://developer.android.com/guide/topics/resources/complex-xml-resources
but this using an inline drawable as resource for another one... i would like to use it in a layout xml
EXAMPLE:
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/round_corner"
android:orientation="horizontal"
android:padding="@dimen/smallMargin">
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/buttonDelete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:drawableTop="@drawable/code"
android:text="@string/delete"
/>
</androidx.appcompat.widget.LinearLayoutCompat>
where code.xml is:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:width="@dimen/popupButtonSize"
android:height="@dimen/popupButtonSize"
android:drawable="@drawable/ic_population" />
</layer-list>
code is only used in that specific layout, is there any way to make it inline?
What seems to be the issue? If you follow the guide it works without a problem:
xmlns:aapt="http://schemas.android.com/aapt"
to root nodeandroid:drawableTop="@drawable/code"
attribute with aapt:attr
childFinal XML will look like this:
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.LinearLayoutCompat
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/round_corner"
android:orientation="horizontal"
android:padding="@dimen/smallMargin">
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/buttonDelete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:text="@string/delete">
<aapt:attr name="android:drawableTop">
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:width="@dimen/popupButtonSize"
android:height="@dimen/popupButtonSize"
android:drawable="@drawable/ic_population" />
</layer-list>
</aapt:attr>
</androidx.appcompat.widget.AppCompatButton>
</androidx.appcompat.widget.LinearLayoutCompat>