让 actionbar 的背景 透明
我需要一个 透明的actionbar ,找到如下方法实现:
1. 首先,设置ActionBar 浮动到主界面上来。
2. 然后,设置ActionBar的背景色,透明或者半透明。
那么如何实现这两步呢?
第一步:
代码实现: 在oncreate中:getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
使用theme 在style中实现: <item name="android:windowActionBarOverlay">true</item>
第二步:
代码实现:
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
|
<style name=
"my_actionbar_style"
parent=
"@android:style/Widget.Holo.Light.ActionBar"
>
<!-- 设置actionbar 背景色 透明 -->
<item name=
"android:background"
>#
33000000
</item>
<item name=
"android:backgroundStacked"
>#346c36</item>
<item name=
"android:backgroundSplit"
>#
33000000
</item>
<item name=
"android:titleTextStyle"
>
@style
/MyActionBarTitleText</item>
</style>
<style name=
"MyActionBarTitleText"
>
<item name=
"android:textColor"
>
@android
:color/white</item>
</style>
|
如何获得 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; }