java.koma
java.koma

Reputation: 208

get drawable from assets xml file

I have a background xml desc file in assets folder, how can i get the drawable obj? xml file as below:

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

<item android:state_focused="false">
    <shape>
        <gradient android:startColor="#2b2c2d" android:endColor="#404142" android:angle="270" />
    </shape>
</item>
<item android:state_focused="true">
    <shape>
        <gradient android:startColor="#2b2c2d" android:endColor="#404142" android:angle="270" />
    </shape>
</item>

Upvotes: 0

Views: 1091

Answers (2)

Shankar Agarwal
Shankar Agarwal

Reputation: 34765

Just place the file in drawable folder and you can get it from there as R.drawwable.filename(through code) and @drawable/yourfilename(through XML).

Generally, You should not place shape.xml files in assets folder. In assets folder we generally place custom fonts, audio file,video file etc.

Upvotes: 1

theelfismike
theelfismike

Reputation: 1621

In your layout, you can set the drawable as the background like so:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="@drawable/drawable_name_without_the_.xml"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"/>

Upvotes: 0

Related Questions