摘要:
为了方便网页和Android应用的交互,Android系统提供了WebView中JavaScript网页脚本调用Java类方法的机制。只要调用addJavascriptInterface方法即可映射一个Java对象到JavaScript对象上。1、映射Java对象到JavaScript对象上mWebView = (WebView) findViewById(R.id.wv_content);mWebView.setVerticalScrollbarOverlay(true);final WebSettings settings = mWebView.getSettings();settings 阅读全文
摘要:
Android系统显示HTML网页的最佳控件为WebView,有时候为了满足特定需求,需要在TextView中显示HTML网页、图片及解析自定义标签。1、TextView显示Html类解析的网页CharSequence richText = Html.fromHtml("<strong>萝卜白菜的博客</strong>--<a href='http://orgcent.com'>http://orgcent.com</a>");mTVText.setText(richText);//此行必须,否则超链接无法点击 阅读全文
摘要:
Android系统中TextView实现跑马灯效果,必须具备以下几个条件:1、android:ellipsize=”marquee”2、TextView必须单行显示,即内容必须超出TextView大小3、TextView要获得焦点才能滚动XML代码:android:ellipsize="marquee", android:singleLine="true"Java代码:mTVText.setText("哼唱接撒砥砺风节雷锋精神http://orgcent.com/,很长很长很长很长很长很长的数据");mTVText.setSingle 阅读全文
摘要:
Android系统默认给TextView插入图片提供了三种方式:1、ImageSpan2、Html.ImageGetter3、TextView.setCompoundDrawables(left, top, right, bottom)1、TextView使用ImageSpan显示图片ImageSpan span = new ImageSpan(this, R.drawable.ic_launcher);SpannableString spanStr = new SpannableString("http://orgcent.com");spanStr.setSpan(sp 阅读全文
摘要:
前面贴过Android系统内部的MediaFile类来获取文件类型的办法,这个类主要是根据文件的扩展名来判断,其准确性不是很好。具体可查看Android系统使用MediaFile类判断音频文件类型。其实,获取文件类型最好的办法便是根据文件头信息来判断。下面贴出相关代码:public class FileType { public static final HashMap<String, String> mFileTypes = new HashMap<String, String>(); static { //images mFileTypes.put("FF 阅读全文