获取ActionBar的高度,背景颜色……

来源:互联网 发布:一搜网络一搜南京同志 编辑:程序博客网 时间:2024/05/18 03:32
刚才在看actionbar_pullto_refresh代码时,看到作者获取有关ActionBar的相关信息时,使用到的方法, 记录下来,
protected Drawable getActionBarBackground(Context context){int[] android_styleable_ActionBar = { android.R.attr.background };// Need to get resource id of style pointed to from actionBarStyleTypedValue outValue = new TypedValue();context.getTheme().resolveAttribute(android.R.attr.actionBarStyle, outValue, true);// Now get action bar style values...TypedArray abStyle = context.getTheme().obtainStyledAttributes(outValue.resourceId, android_styleable_ActionBar);try{ return abStyle.getDrawable(0);}finally{abStyle.recycle();}}/**获取ActionBar的高度*/protected int getActionBarSize(Context context){int[] attrs = { android.R.attr.actionBarSize };TypedArray values = context.getTheme().obtainStyledAttributes(attrs);try{return values.getDimensionPixelSize(0, 0);//第一个参数数组索引,第二个参数 默认值}finally{values.recycle();}}}

0 0
原创粉丝点击