ActionBarSherlock学习笔记——知识点

来源:互联网 发布:站长seo查询 编辑:程序博客网 时间:2024/05/21 16:22

SplitActionBar

1.当布局变窄的时候,ActionBar可以分割,分上下

1 android:uiOptions="splitActionBarWhenNarrow"

 2.ActionBar换背景色

 1             /** 2              * 获得图片资源 3              */ 4             BitmapDrawable bg = (BitmapDrawable) getResources().getDrawable( 5                     R.drawable.bg_striped_img); 6             BitmapDrawable bg_bar = (BitmapDrawable) getResources() 7                     .getDrawable(R.drawable.bg_striped_split_img); 8             /** 9              * 设置重复方向10              */11             bg.setTileModeXY(TileMode.REPEAT, TileMode.REPEAT);12             bg_bar.setTileModeXY(TileMode.REPEAT, TileMode.REPEAT);13             /**14              * 设置背景图15              */16             getSupportActionBar().setBackgroundDrawable(bg);17             getSupportActionBar().setSplitBackgroundDrawable(bg_bar);

需要判断版本信息 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {

 3.监听返回按钮:

    // 监听返回按钮    @Override    public boolean onOptionsItemSelected(MenuItem item) {        // TODO Auto-generated method stub        if (item.getItemId() == android.R.id.home) {            finish();            return true;        }        return super.onOptionsItemSelected(item);    }

 4.ActionBar中的item的显示和隐藏

清除:mMenu.clear();显示/刷新:invalidateOptionsMenu();

 

0 0