首页 > 移动平台 > 详细

android 自定义标题栏 titleBar自定义

时间:2014-01-15 23:45:28      阅读:599      评论:0      收藏:0      [点我收藏+]

在value文件夹下添加style.xml

bubuko.com,布布扣
<?xml version="1.0" encoding="utf-8"?>
<resources>

    <!--————————————————标题栏的设置————————————————————————-->
    <!--设置一个背景信息-->
    <style name="title_bar_bg_blue">
        <item name="android:background">@drawable/bg_titlebar</item>
    </style>

    <style name="theme_title_bar_blue" parent="android:Theme">
        <!--设置标题栏的高度-->
        <item name="android:windowTitleSize">45dp</item>
        <!--设置标题栏的背景-->
        <item name="android:windowTitleBackgroundStyle">@style/title_bar_bg_blue</item>
    </style>
    <!--————————————————标题栏的设置 结束————————————————————————-->
</resources>
bubuko.com,布布扣

再在layout文件夹下定义自定义标题的xml:

bubuko.com,布布扣
<?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"
        >

    <!--居中显示-->
    <TextView
            android:text="首页"
            android:textSize="25sp"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>

</RelativeLayout>
bubuko.com,布布扣

然后在这个activity中按以下顺序定义:

        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
        setContentView(R.layout.maintabs);
        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
                R.layout.title_bar_first);

最后在清单文件中,相应的activity添加这个属性:

android:theme="@style/theme_title_bar_blue"

android 自定义标题栏 titleBar自定义

原文:http://www.cnblogs.com/wuyou/p/3515422.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!