TextViewまたはToastフォーマットされたhtml文字列を表示
s
s
TextViewまたはToastフォーマットされたhtml文字列を表示
//上の画像のロードは同期的にネットワークからダウンロードされ、キャッシュされていません.実際に使うには最適化が必要です.ここはただの機能Demo
//上のalign='center'属性は有効ではありません.私は支持しないだろう.
s
s
s
TextViewまたはToastフォーマットされたhtml文字列を表示
((Button) findViewById(R.id.button_test_toast1)).setOnClickListener(new OnClickListener() {
public void onClick(View v) {
//ToastUtil.ToastShort(MainActivity.this, " !
");
//ToastUtil.ToastShort(MainActivity.this, Html.fromHtml("<h1 align='center'> !</h1><p><font color='red'> </font><u> </u><i> </i></p>"));
Spanned sp = Html.fromHtml("<h1 align='center'> !</h1><p><font color='red'> </font><u> </u><i> </i><img src='https://www.google.com.hk/intl/zh-CN/images/logo_cn.png' /></p>", new Html.ImageGetter() {
@Override
public Drawable getDrawable(String source) {
InputStream is = null;
try {
is = (InputStream) new URL(source).getContent();
Drawable d = Drawable.createFromStream(is, "src");
d.setBounds(0, 0, d.getIntrinsicWidth(),
d.getIntrinsicHeight());
is.close();
return d;
} catch (Exception e) {
return null;
}
}
}, null);
ToastUtil.ToastShort(MainActivity.this, sp);
}
});
//上の画像のロードは同期的にネットワークからダウンロードされ、キャッシュされていません.実際に使うには最適化が必要です.ここはただの機能Demo
//上のalign='center'属性は有効ではありません.私は支持しないだろう.
public static void ToastShort(Context context, CharSequence text) {
Toast.makeText(context, text, Toast.LENGTH_SHORT).show();
}
s
s