首先样式的修改组要是在res/values/styles文件中做修改:
大上分为三个步骤:
1、在如下代码中添加:<item name="android:actionBarStyle" >@style/myActionBarStyle</item>
- <style name="AppTheme" parent="AppBaseTheme">
- <!-- All customizations that are NOT specific to a particular API-level can go here. -->
-
- </style>
2、增加第一步中的被引用样式的具体内容
- <style name="myActionBarStyle" parent="android:Widget.ActionBar" >
- <item name="android:background"></span>写上要的背景颜色</item>
- <item name="android:titleTextStyle">@style/titleStyle</item> 此处为你要的标题颜色
- <item name="android:backgroundSplit">写上要的背景颜色</item>此处为底部操作栏的颜色(有些时候需要显示底部操作栏比如魅族手机应特别注意此项)
- </style>
3、同样的第三步增加第二步中引用样式的具体内容:
- <style name="titleStyle">
- <item name="android:textSize">写上文字大小</item>
- <item name="android:textColor">写上文字颜色</item>
这样就完成了actionbar的样式的基本自定义,较为复杂的这里就不写了。后了本人还发现现在许多app都要求actionbar的标题要居中去显示,下面贴出一种方法解决这个问题
1、自己写一个布局文件
- <span style="font-size:14px;"><?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:gravity="center_vertical"
- android:paddingLeft="10dp"
- android:paddingRight="10dp" >
- <TextView
- android:id="@+id/anctionbar_title"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:textSize="25sp"
- android:textColor="#FFFFFFFF"
- android:layout_centerInParent="true"
- android:text="标题"
- />
- </RelativeLayout>
- </span>
2、在actionBar的显示处写下如下代码
//隐藏掉系统本身的标题
getActionBar().setDisplayShowTitleEnabled(false);
// 显示自定义视图
getActionBar().setDisplayShowCustomEnabled(true);
//此处自定义了一个actionbar为了让标题居中显示
actionbarLayout = LayoutInflater.from(this).inflate(R.layout.actionbar_layout, null);
getActionBar().setCustomView(
actionbarLayout,
new ActionBar.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
ActionBar.LayoutParams mP = (ActionBar.LayoutParams) actionbarLayout
.getLayoutParams();
mP.gravity = mP.gravity & ~Gravity.HORIZONTAL_GRAVITY_MASK
| Gravity.CENTER_HORIZONTAL;
getActionBar().setCustomView(actionbarLayout, mP);