actionbaractionsherlockk如何自定义title

android UI
扫扫二维码,随身浏览文档
手机或平板扫扫即可继续访问
Meizu Smart Bar开发指南1.1.0
举报该文档含有违规或不良信息。
反馈该文档无法正常浏览。
举报该文档为重复文档。
推荐理由:
将文档分享至:
分享完整地址
文档地址:
粘贴到BBS或博客
flash地址:
支持嵌入FLASH地址的网站使用
html代码:
&embed src='/DocinViewer-4.swf' width='100%' height='600' type=application/x-shockwave-flash ALLOWFULLSCREEN='true' ALLOWSCRIPTACCESS='always'&&/embed&
450px*300px480px*400px650px*490px
支持嵌入HTML代码的网站使用
您的内容已经提交成功
您所提交的内容需要审核后才能发布,请您等待!
3秒自动关闭窗口Android下保存简单网页到本地(包括简单图片链接转换)_Linux编程_Linux公社-Linux系统门户网站
你好,游客
Android下保存简单网页到本地(包括简单图片链接转换)
来源:Linux社区&
作者:nekocode
最近在做一个项目涉及到将包含图片的简单网页下载到本地,方便离线时观看,在这里分享一下,大家做下简单修改就可以用到自己的项目中了。(这里用到了AQuery库)
package com.nekocode.xuedao.
import java.io.Fimport java.io.FileOutputSimport java.util.ArrayLimport java.util.regex.Mimport java.util.regex.P
import .content.ContentVimport android.content.Cimport android.database.Cimport android.database.sqlite.SQLiteD
import com.androidquery.AQimport com.androidquery.callback.AjaxCimport com.androidquery.callback.AjaxSimport com.nekocode.xuedao.PublicDimport com.nekocode.xuedao.PublicData.S
public class HtmlStorageHelper {&private String URL = "/fetchurl.php/getcontent/";&private PublicD&private AQ&private SQLiteDatabase mDB;&private String mDownloadP&&public HtmlStorageHelper(Context context) {& pd = PublicData.getInstance();& aq = new AQuery(context);& mDB = context.openOrCreateDatabase("data.db", Context.MODE_PRIVATE, null);& mDB.execSQL("create table if not exists download_html(_id INTEGER PRIMARY KEY AUTOINCREMENT, content_id TEXT NOT NULL, title TEXT NOT NULL)");& & mDownloadPath = pd.mAppPath + "download/";& File dir_file = new File(pd.mAppPath + "download/");& if(!dir_file.exists())& &dir_file.mkdir();&}&&public void saveHtml(final String id, final String title) {& if(isHtmlSaved(id))& && & aq.ajax(URL+id, String.class, new AjaxCallback&String&() {& &@Override& &public void callback(String url, String html, AjaxStatus status) {& & File dir_file = new File(mDownloadPath + id);& & if(!dir_file.exists())& & &dir_file.mkdir();& & & & Pattern pattern = pile("(?&=src=\")[^\"]+(?=\")");& & Matcher matcher = pattern.matcher(html);& & StringBuffer sb = new StringBuffer(); & & while(matcher.find()){& & &downloadPic(id, matcher.group(0));& & &matcher.appendReplacement(sb, formatPath(matcher.group(0))); & & }& & matcher.appendTail(sb);& & html = sb.toString();& & & & writeHtml(id, title, html);& &}& });&}&&private void downloadPic(String id, String url) {& File pic_file = new File(mDownloadPath + id + "/" + formatPath(url));& aq.download(url, pic_file, new AjaxCallback&File&() {& &@Override& &public void callback(String url, final File file, AjaxStatus status) {& &}& });&}&&private void writeHtml(String id, String title, String html) {& File html_file = new File(mDownloadPath + id + "/index.html");& FileOutputStream fos =& try {& &fos=new FileOutputStream(html_file);& & & & & & fos.write(html.getBytes());& & & & } catch (Exception e) {& & & & & & e.printStackTrace();& & & & }finally{& & & & & & try {& & & & & & & & fos.close();& & & & & & } catch (Exception e2) {& & & & & & & & e2.printStackTrace();& & & & & & }& & & & }& & ContentValues values = new ContentValues();& values.put("content_id", id);& values.put("title", title);& mDB.insert("download_html", "_id", values);&}&&public boolean isHtmlSaved(String id) {& File file = new File(mDownloadPath + id);& if(file.exists()) {& &file = new File(mDownloadPath + id + "/index.html");& &if(file.exists())& && }& deleteHtml(id);&&}&&public String getTitle(String id) {& Cursor c = mDB.rawQuery("select * from download_html where content_id=?", new String[]{id});& if(c.getCount() == 0)& && & c.moveToFirst();& int index1 = c.getColumnIndex("title");& & return c.getString(index1);&}&&public ArrayList&Subscribe& getHtmlList() {& Cursor c = mDB.rawQuery("select * from download_html", null);& ArrayList&Subscribe& list = new ArrayList&Subscribe&();& if(c.getCount() != 0) {& &c.moveToFirst();& &int index1 = c.getColumnIndex("content_id");& &int index2 = c.getColumnIndex("title");& && &while (!c.isAfterLast()) {& & String id = c.getString(index1);& & if(isHtmlSaved(id)) {& & &Subscribe sub = new Subscribe(& & & &id,& & & &c.getString(index2),& & & &Subscribe.FILE_DOWNLOADED& & & &);& & &list.add(sub);& & }& & & & c.moveToNext();& &}& }& &&}&&public void deleteHtml(String id) {& mDB.delete("download_html", "content_id=?", new String[]{id});& File dir_file = new File(mDownloadPath + id);& deleteFile(dir_file);&}
&private void deleteFile(File file) {& if (file.exists()) { // 判断文件是否存在& &if (file.isFile()) { // 判断是否是文件& & file.delete(); // delete()方法 你应该知道 是删除的意思;& &} else if (file.isDirectory()) { // 否则如果它是一个目录& & File files[] = file.listFiles(); // 声明目录下所有的文件 files[];& & for (int i = 0; i & files. i++) { // 遍历目录下所有的文件& & &this.deleteFile(files[i]); // 把每个文件 用这个方法进行迭代& & }& &}& &file.delete();& } else {& &//& }&}&&private String formatPath(String path) {& & & & if (path != null && path.length() & 0) {& & & & & & path = path.replace("\\", "_");& & & & & & path = path.replace("/", "_");& & & & & & path = path.replace(":", "_");& & & & & & path = path.replace("*", "_");& & & & & & path = path.replace("?", "_");& & & & & & path = path.replace("\"", "_");& & & & & & path = path.replace("&", "_");& & & & & & path = path.replace("|", "_");& & & & & & path = path.replace("&", "_");& & & & }& & & && & }}
更多Android相关信息见 专题页面
相关资讯 & & &
图片资讯 & & &
   同意评论声明
   发表
尊重网上道德,遵守中华人民共和国的各项有关法律法规
承担一切因您的行为而直接或间接导致的民事或刑事法律责任
本站管理人员有权保留或删除其管辖留言中的任意内容
本站有权在网站内转载或引用您的评论
参与本评论即表明您已经阅读并接受上述条款12168人阅读
& & & &每一位Android开发者对Action Bar这种设计都不陌生了,毕竟它已经发布了至少两年了。Android团队发布设计规范时同时放出了的Api来支持这种设计。如果对ActionBar不太熟悉的可以参考《&》。ActionBar的API被添加在Android3.0(API 级别 11)中,低版本的还是用不了,根本不能适配支持Android 2.X系列的应用。很幸运有第三方开源的支持使得Android 2.1以上的Android应用使用actionbarsherlock定义的Action Bar。这里我们不介绍actionbarsherlock怎么使用,我们介绍一种更新的官方支持的&使得Android2.1以上的版本可以实现Action Bar。& &&Google I/O 2013中AppCompat实现的Action Bar效果& & & &AppCompat在最新的API 18的Android Support Library中。使用AppCompat需要以库的形式引入到应用中,AppCompat在&sdk&/extras/android/support/v7/appcompat/&的位置,需要自行下载,或者升级SDK。& & & &如果应用是使用actionbarsherlock实现的Action Bar,也不必刻意的改成AppCompat。因为actionbarsherlock是一个很稳定的经过很多开发者验证的开发库。
ActionBarSherlock is a solid and well-tested library which has served developers very well for a long time.
If you are already using it and do not currently require any of the above then there is no need to migrate.
1)导入AppCompat库& & & 使用AppCompat第一步需要导入AppCompat库,这一步就不做详细介绍了。2)修改&android:theme每个使用Action Bar的Activity都应该添加Android:theme&activity
android:theme=&@style/Theme.AppCompat& /&或者修改application &application
android:label=&@string/app_name&
android:icon=&@drawable/ic_launcher&
android:theme=&@style/Theme.AppCompat&
android:allowBackup=&true&&3)Activity要继承自ActionBarActivity& & & & 实现Action Bar的视图需要继承ActionBarActivity。4)修改menu的命名空间&menu xmlns:android=&/apk/res/android&
xmlns:holo=&/apk/res-auto& &
android:id=&@+id/action_websearch&
android:icon=&@drawable/action_search&
android:title=&@string/action_websearch&
holo:showAsAction=&never&/&
&/menu&& & & 要特别注意的是,通过XML文件来实现Action Item,一定要自定义命名空间,而且该命名空间的后缀一定要和item中showAsAction的前缀一致,本例中为“holo”显示Menu需要重写onCreateOptionsMenu方法: @Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);
return super.onCreateOptionsMenu(menu);
对Menu的item事件处理需要重写onOptionsItemSelected方法。@Override
public boolean onOptionsItemSelected(MenuItem item) {
// The action bar home/up action should open or close the drawer.
// ActionBarDrawerToggle will take care of this.
if (mDrawerToggle.onOptionsItemSelected(item)) {
// Handle action buttons
switch(item.getItemId()) {
case R.id.action_websearch:
// create intent to perform web search for this planet
Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
intent.putExtra(SearchManager.QUERY, getSupportActionBar().getTitle());
// catch event that there's no activity to handle intent
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
Toast.makeText(this, R.string.app_not_available, Toast.LENGTH_LONG).show();
return super.onOptionsItemSelected(item);
上面就是简单的通过Appcompat实现Action Bar,想自定义各种属性请参考官方文档。demo下载:/*** @author 张兴业* &* &iOS入门群:* &android开发进阶群:* &我的新浪微博:*/参考:/actionbarcompat-how-to-use//actionbarcompat-action-views/http://android-/2013/08/actionbarcompat-and-io-2013-app-source.html
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:1995541次
积分:22014
积分:22014
排名:第99名
原创:269篇
转载:195篇
译文:20篇
评论:1299条
android 开发交流
济南移动互联网:
文章:10篇
阅读:118079
文章:18篇
阅读:123624
阅读:49377
文章:11篇
阅读:67620
文章:14篇
阅读:82649
文章:59篇
阅读:586300
(1)(1)(2)(4)(2)(3)(1)(2)(6)(1)(6)(5)(11)(3)(1)(7)(7)(7)(4)(5)(1)(1)(5)(1)(10)(11)(7)(5)(1)(2)(1)(8)(4)(4)(8)(23)(23)(1)(1)(1)(3)(9)(15)(34)(11)(5)(3)(3)(1)(5)(2)(5)(14)(23)(22)(25)(46)(7)(9)(30)(8)(1)(5)(1)

我要回帖

更多关于 自定义 的文章

 

随机推荐