简体   繁体   中英

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>

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.

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"/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM