您的位置:首页 > 移动开发 > Android开发

android_actionbar自定义标题栏

2013-06-26 10:51 429 查看

一. Android 修改actionbar的高度:

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

1. style.xml代码贴上:

[java]
view plaincopy

<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属性讲解:/article/8912038.html#
http://blog.csdn.net/dadaxiaoxiaode/article/details/8915088
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: