requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);

setContentView(R.layout.main);

//自定义标题栏
        mWindow = getWindow();
        mWindow.setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.titlebar);

titlebar.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TextView
android:text="@string/app_name"
android:textColor="#000"
android:paddingRight="3.0dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:text="@string/battery_text"
android:textColor="#000"
android:paddingRight="3.0dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/battery_text"
android:textColor="#00f"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>

上述的话只是适合android4.0一下的版本,如果需要针对android4.0以上的版本的话需要我们使用自己的样式

  <style name="TitleBackgroundColor">
<item name="android:background">@color/background_color</item>
</style> <style name="titlestyle" parent="android:Theme" >
<item name="android:windowTitleSize">40dip</item>
<item name="android:windowTitleBackgroundStyle">@style/TitleBackgroundColor</item>
</style>
然后在配置文件中加上,OK
<activity android:name="com.ygl.ui.LoginActivity"
android:theme="@style/titlestyle" ></activity>

最新文章

  1. appium 环境搭建 java
  2. 一起学HTML基础-格式与布局fixed/absolute/relative/z-index/float
  3. 【iCore3 双核心板】例程二十:LAN_TCPC实验——以太网数据传输
  4. asp接收jquery post 中文乱码问题!
  5. Unity Scripting Tutorials 要点记录
  6. Fatjar成功安装记录
  7. 使用Calendar获取近三年的财务信息
  8. 关于std::string
  9. poj3414(bfs)
  10. Vim快捷键大全
  11. 身为运维的你,怎么掌握python才不会失业
  12. javascript实现继承3种方式: 原型继承、借用构造函数继承、组合继承,模拟extends方法继承
  13. AllocateHWnd SetTimer API
  14. 基于Manhattan最小生成树的莫队算法
  15. Container Adaptors
  16. Python学习笔记——Python Number(数字)
  17. 牛客网-《剑指offer》-调整数组顺序使奇数位于偶数前面
  18. oracle dblink 查询 tns:无法解析指定的连接标识符
  19. curl 一个无比有用的网站开发工具
  20. 腾讯云-搭建 WordPress 个人博客

热门文章

  1. beautifulsoup小节
  2. Net 通用权限管理系统源码 带数据库设计文档,部署说明文档
  3. Redis在windows下安装和PHP中使用
  4. Java 占位符使用 和 修饰符
  5. php js =&gt; splice 数组 插入 功能
  6. HTML之电话: 邮箱: 网址
  7. selenium第二课(脚本录制seleniumIDE的使用)
  8. JSON 的应用
  9. bootstrap的html模版
  10. SQL 统计整个服务器上各个数据库占用的空间