Android Actionbar自定义标题栏

一. Android 修改actionbar的高度:

一直很纠结actionbar的高度该如何修改,现在就简单介绍一下,actionbar的高度由actionBarSize 属性决定,所以你你只要找到parent中带有该actionBarSize的属性,然后重新定义一个style就行了,例如:@android:style/Theme、@android:style/Theme.Holo 、@android:style/Theme.Holo.Light 等。

 

1. style.xml代码贴上:

<span style="font-size:18px;"><resources xmlns:android="http://schemas.android.com/apk/res/android">

    <style name="CustomTitleSize" parent="@android:style/Theme.Holo.Light">
        <item name="android:actionBarSize">100dip</item>
    </style>

</resources>


</span>

 

2. 在manifest.xml中的

<application
        android:label="@string/app_name"
        android:theme="@style/CustomTitleSize"
        android:icon="@drawable/ic_launcher"
         >

 

引用该样式,就可以达到修改actionbar的高度的目的。

 

注:android4.0里边有values-v11,values-v14两个文件夹分别对应的是android3.0和Andorid4.0以上,所以你可以根据不同的设备分别在文件夹里定义style.xml文件

 

二:解决Actionbar自定义标题栏不能填充满的问题:

// 自定义标题栏
  getActionBar().setDisplayShowHomeEnabled(false);
  getActionBar().setDisplayShowTitleEnabled(false);
  getActionBar().setDisplayShowCustomEnabled(true);

//加载标题栏布局
  LayoutInflater mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  View mTitleView = mInflater.inflate(R.layout.custom_action_bar_layout,null);

//显示布局,通过这种方式你会发现宽度没有填充满父容器,解决之道:添加属性控制
  getActionBar().setCustomView(mTitleView);
  
//显示布局,通过这种方式你会发现宽度可以正常填充满父容器
  getActionBar().setCustomView(mTitleView,new ActionBar.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT));
 

 

 

 

 

Actionbar属性讲解:http://blog.csdn.net/sunyouhao/article/details/7862017#

posted @ 2013-05-11 19:18  行走的思想  阅读(12)  评论(0编辑  收藏  举报  来源