|
iApp的图片控件默认是不支持显示网络地址图片的,但是我们在调用java的一些方法后可以直接让部分控件可以直接显示网络图片。
//首先新建一个Http.mjava文件写入以下代码
import android.app.*;
import android.content.*;
import android.graphics.*;
import android.net.*;
import java.io.*;
import java.net.*;
import android.graphics.drawable.*;
//获取网络图片
public static BitmapDrawable getInternetPicture(String UrlPath) {
Bitmap bm = null;
String urlpath = UrlPath;
try {
URL uri = new URL(urlpath);
HttpURLConnection connection = (HttpURLConnection) uri.openConnection();
connection.setRequestMethod("GET");
connection.setReadTimeout(5000);
connection.setConnectTimeout(5000);
connection.connect();
if (connection.getResponseCode() == 200) {
InputStream is = connection.getInputStream();
bm = BitmapFactory.decodeStream(is);
} else {
bm = null;
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return new BitmapDrawable(bm);
}
//然后在.iyu界面里载入事件上写入以下代码
t()
{
s bgurl = " call(bg,"mjava","Http.getInternetPicture",bgurl)
ufnsui()
{
us(1,"background",bg)
}
}
|
|