android默认的标题栏确实有点不敢恭维,有时为了实现个性化的需求需要自定义一套自己的标题栏。下面就来说说两种实现自定义标题栏的方法。
1、利用Activity的requestWindowFeature方法激活window features。再通过window的setFeatureInt方法设定事先定义好的布局文件。
具体代码如下:

protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);         requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);        // 这里要主要requestWindowFeature和setContentView先后顺序哦        setContentView(R.layout.custom_title);        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title_1);}


custom_title_1为自定义的标题栏布局文件。
2、通过在manifest文件中设置需要自定义标题栏的Activity的主题。如下:

<activity android:name=".main.About" android:label="@string/about"android:theme="@style/MyCustom"></activity> <activity android:name=".main.Help" android:label="@string/help"android:theme="@style/MyCustom"></activity>


在res/values/styles.xml文件中定义好自己的样式

<?xml version="1.0" encoding="utf-8"?><resources>    <style name="MyCustom" parent="android:style/Theme.Light">    <item name="android:windowTitleBackgroundStyle">@style/titleBg</item>    <item name="android:windowTitleSize">36dp</item>    <item name="android:windowTitleStyle">@style/titleText</item>    </style>     <style name="titleBg">        <item name="android:layout_width">match_parent</item>        <item name="android:layout_height">wrap_content</item>        <item name="android:background">#63B2D6</item>        <item name="android:paddingLeft">20dp</item>    </style>    <style name="titleText">        <item name="android:textSize">23sp</item>        <item name="android:textColor">#424952</item>    </style></resources>


ok,基本就是这样,下面贴一个效果图
2种自定义android标题栏titleBar的方法
android titlebar

更多相关文章

  1. Android Environment 的作用以及常用的方法
  2. [置顶] Android中资源文件的详解和android中的单位介绍
  3. android(drawable文件夹)图片适配
  4. Android控件布局属性全解
  5. android中的五大布局和过程流向
  6. Android资源文件使用经验
  7. Android Studio 中方法数65536 或超过64K的解决方案
  8. Android SDK使用迅雷下载方法

随机推荐

  1. MySQL 5.7.17压缩版安装笔记
  2. linux下mysql 5.7.16 免安装版本图文教程
  3. MySQL实现类似于connect_by_isleaf的功能
  4. MySQL的查询计划中ken_len的值计算方法
  5. navicat中创建存储过程、触发器和使用游
  6. MySQL实现当前数据表的所有时间都增加或
  7. Mysql5.7忘记root密码怎么办(简单且有效方
  8. MySql允许远程连接如何实现该功能
  9. MySQL5.7.10 安装文档教程详解
  10. MySQL 序列 AUTO_INCREMENT详解及实例代