Android downloading external resources analysis problem

The following XML resources in res directory can be automatically compiled by ID references. But if the document is stored in the memory card from external download, to a drawable class to how do.
Please gurus teach

The following is a background button XML settings

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="">

<item android:state_pressed="true"> <!- defined when the button is in the pressed state form. -->
<solid android:color="#cc2222" />

<stroke android:width="1dp" android:color="#00000000" />

<corners android:radius="8dp" />

<padding android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp" />
<item android:state_enabled="false"> <!- definition when form -- button disable.>
<solid android:color="#aa0000" />

<stroke android:width="2dp" android:color="#80808080" />

<corners android:radius="8dp" />

<padding android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp" />
<item> <!-- definition form:>
<gradient android:angle="-90" android:endColor="#730201" android:startColor="#C4120E" />

<stroke android:width="1dp" android:color="#00000000" />

<corners android:radius="5dp" />

<padding android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp" />


Started by Bard at February 01, 2016 - 8:28 PM

Posted by Bard at February 15, 2016 - 8:56 PM

Android byte into the drawble, the first copy XML to data/data/package in byte into drawable can be

Posted by Page at December 14, 2016 - 3:16 PM

Can specifically by toDrawable method

Posted by Bard at December 24, 2016 - 3:43 PM

He used a static method (Drawable createFromXml).:
public static Drawable createFromXml (Resources r, XmlPullParser parser)

The following is a simple example code, the principle is to read out the XML file to the FileReader object, and then as a XmlPullParser object can be input stream.

XmlPullParser xmlParser = null;
File file = new File("your storage xml file path");

FileReader fileReader = null;
try {
fileReader = new FileReader(file);
xmlParser = Xml.newPullParser();
Drawable drawable = Drawable.createFromXml(getResources(), xmlParser);

} catch (FileNotFoundException e) {

} catch (Exception e) {

} finally {
try {
if (fileReader != null) {
} catch (IOException e) {

Posted by Reed at December 31, 2016 - 3:48 PM

You download the file into a byte, then the byte into drawable and then transformed into bitmap

Posted by Page at January 01, 2017 - 4:43 PM

Should be the external address can not be used.

Posted by Edith at January 05, 2017 - 5:54 PM

The resource is available to download images, does not work on XML files. Download. 9.png tried to have problems, the resource of draw9patch, NinePatchDrawable construction method, edge angle becomes small.,

Posted by Bard at January 09, 2017 - 6:58 PM

The Drawable.createFromXml method should be used within the XML, using the res drawable Id no problem, copy your code, analytic outside the file will be abnormal, return null

Posted by Bard at January 11, 2017 - 7:55 PM

In simple terms, you are reading the file by binary, generate the corresponding Bitmap OK in Android

Posted by Yehudi at January 12, 2017 - 6:51 PM

Which sentence code returns an empty?

Posted by Reed at January 13, 2017 - 5:14 PM