Sunday, February 9, 2014

android download external resources to resolve problems


            
The following xml in resource-res directory can be automatically compiled referenced by id. However, if the document is downloaded from an external memory to the memory card, how to resolve a drawable class.
Please enlighten
cattle
Here is the background of a button in xml settings

  


<-! defined state when the button is pressed form. ->









<-! defined time when button disable form ->









<-! defined shape ->











Reply:

Reply:
android byte converted into drawble, the first copy to the xml data / data / package using byte can be converted into a drawable
Reply:
reference to the second floor lieri111 reply:
android byte converted into drawble, the first copy to the xml data / data / package using byte can be converted into a drawable a
Can specific point method under toDrawable
Reply:
Drawable landlord static method createFromXml () try:
public static Drawable createFromXml (Resources r, XmlPullParser parser)

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

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

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

} Catch (FileNotFoundException e) {

} Catch (Exception e) {

} Finally {
try {
if (fileReader! = null) {
fileReader.close ();
}
} Catch (IOException e) {
}
}

Reply:
reference to the third floor QQ718225250 reply:
Quote: references to the second floor lieri111 reply:

android byte converted into drawble, the first copy to the xml data / data / package using byte can be converted into a drawable
Can specific point under toDrawable method

http://blog.sina.com.cn/s/blog_4607d856010125sl.html

You downloaded files into byte, then by byte then converted into bitmap drawable
Reply:
Should not be an external address to use it
Reply:
references, 5th Floor lieri111 reply:
Quote: references to the third floor QQ718225250 reply:

Quote: references to the second floor lieri111 reply:

android byte converted into drawble, the first copy to the xml data / data / package using byte can be converted into a drawable
Can specific point under toDrawable method

http://blog.sina.com.cn/s/blog_4607d856010125sl.html

You downloaded files into byte, then by byte then converted into a drawable bitmap
This resource is available for download with a picture of the xml file does not work. Download. 9.png tried to have problems, draw9patch resources, after NinePatchDrawable constructor, smaller corners,
Reply:
references, 4th Floor ncepu307 reply:
landlord Drawable static method createFromXml () try:
public static Drawable createFromXml (Resources r, XmlPullParser parser)

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

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

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

} Catch (FileNotFoundException e) {

} Catch (Exception e) {

} Finally {
try {
if (fileReader! = null) {
fileReader.close ();
}
} Catch (IOException e) {
}
}
Drawable.createFromXml method should be used for internal xml, use the drawable id res no problem, copy your code, an exception will be resolved outside of the file, returns null
Reply:
simple terms, you're reading via binary file, generate the corresponding Bitmap in Android in the OK
Reply:
reference to the 8th floor QQ718225250 reply:
Quote: references to the 4th floor ncepu307 reply:

Drawable landlord static method createFromXml () try:
public static Drawable createFromXml (Resources r, XmlPullParser parser)

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

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

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

} Catch (FileNotFoundException e) {

} Catch (Exception e) {

} Finally {
try {
if (fileReader! = null) {
fileReader.close ();
}
} Catch (IOException e) {
}
}
Drawable.createFromXml method should be used for internal xml, use the drawable id res no problem, copy your code, an exception will be resolved outside of the file, returns null

NOT true code returns empty?
Reply:
xmlParser = Xml.newPullParser (); and Drawable.createFromXml (getResources (), xmlParser);
The xmlParser type mismatch fact, I told the source code. Eventually returned drawable is empty.

If I write an analytic category, it seems too difficult. But now reduced customer demand, simply set the color of the lines and so on. It is a new problem encountered is
There are two methods GradientDrawable setColors (int [] colors) setOrientation () API Level16 is added, I need to support the 2.3 seems these two methods have to write their own, but this is another issue a new one.

Thank ncepu307

No comments:

Post a Comment