android开发让 actionbar 透明

android开发让 actionbar 透明_第1张图片

 让 actionbar 的背景 透明

我需要一个 透明的actionbar ,找到如下方法实现:

1. 首先,设置ActionBar 浮动到主界面上来。

2. 然后,设置ActionBar的背景色,透明或者半透明。

 

那么如何实现这两步呢?

第一步:

代码实现: 在oncreate中:getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);

使用theme 在style中实现: true 

第二步:

代码实现:

ActionBar actionBar = getActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#33000000")));
//google的actionbar是分为上下两栏显示的,上面的代码只能设置顶部actionbar的背景色,
//为了让下面的背景色一致,还需要添加一行代码:
actionBar.setSplitBackgroundDrawable(new ColorDrawable(Color.parseColor("#33000000")));
        

使用theme 在style中实现:

按 Ctrl+C 复制代码
按 Ctrl+C 复制代码

 

如何更改action的文本颜色?

1
2
3
4
5
6
7
8
9
10
11
12
 
   

  

 如何获得 actionbar的高度?

复制代码
    public static int getActionbarHeight(Activity context) {
         int actionBarHeight = 0;
         // Calculate ActionBar height
         TypedValue tv = new TypedValue();
         if (context.getTheme().resolveAttribute(android.R.attr.actionBarSize,
         tv, true))
         {
         actionBarHeight =
         TypedValue.complexToDimensionPixelSize(tv.data,context.getResources().getDisplayMetrics());
         }
         return actionBarHeight;
    }
复制代码

你可能感兴趣的:(android)