博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Andorid 自定义标题栏
阅读量:4683 次
发布时间:2019-06-09

本文共 1749 字,大约阅读时间需要 5 分钟。

http://blog.csdn.net/mimitracely/article/details/7968944

先在strings.xml 中定义主题

[html] 
  1.    <style name="customTitlebg" >  
  2.     <item name="android:background">@drawable/title_bg</item>  
  3. </style>  
  4.      
  5. <style name="titlebar" parent="android:Theme">  
  6.     <item name="android:windowTitleSize">40dp</item>   
  7.     <item name="android:windowTitleBackgroundStyle">@style/customTitlebg</item>   
  8. </style>  
在AndroidManifest.xml,application标签中改为使用我们自定义的主题

[html] 
  1. <application  
  2.         android:icon="@drawable/ic_launcher"  
  3.         android:label="@string/app_name"  
  4.         android:theme="@style/titlebar" >  
  5.         <activity  
  6.             android:name=".MainActivity"  
  7. ...  
下面是自定义标题栏的实现 title_bar.xml

[html] 
  1. <?xml version="1.0" encoding="utf-8"?>   
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"   
  3.     android:orientation="horizontal" android:layout_width="fill_parent"   
  4.     android:layout_height="fill_parent">  
  5.     <ImageView android:layout_width="wrap_content"   
  6.         android:layout_centerVertical="true"  
  7.         android:layout_height="wrap_content"   
  8.         android:src="@drawable/title_home_normal" />  
  9.       
  10.     <TextView android:layout_width="wrap_content"   
  11.         android:layout_centerInParent="true"   
  12.         android:layout_height="wrap_content"   
  13.         android:textColor="#000000"  
  14.         android:text="自定义标题栏" />  
  15.   
  16.     <ImageView  
  17.         android:layout_width="wrap_content"  
  18.         android:layout_height="wrap_content"  
  19.         android:layout_alignParentRight="true"  
  20.         android:layout_centerVertical="true"  
  21.         android:src="@drawable/title_new_normal" />  
  22.   
  23. </RelativeLayout>  
最后修改Activity
[java] 
  1. public void onCreate(Bundle savedInstanceState) {  
  2.     super.onCreate(savedInstanceState);  
  3.     requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); //声明使用自定义标题   
  4.     setContentView(R.layout.tabhost);  
  5.     getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_bar);//自定义布局赋值   
  6. }  

转载于:https://www.cnblogs.com/zsw-1993/archive/2012/09/27/4880839.html

你可能感兴趣的文章
2018年开局第一场“风口”---区块链,最致命的5个坑。
查看>>
【模式识别与机器学习】——SVM举例
查看>>
【转】IT名企面试:微软笔试题(1)
查看>>
IO流入门-第十章-DataInputStream_DataOutputStream
查看>>
「BZOJ2152」聪聪可可
查看>>
关于Python文档读取UTF-8编码文件问题
查看>>
IT人不可不听的10个故事
查看>>
网络营销之我见
查看>>
DRF的分页
查看>>
hashCode()
查看>>
Docker容器学习与分享03
查看>>
phpmyadmin万能密码
查看>>
缓存 - 浏览器缓存
查看>>
html td 限制 高度 和 宽度
查看>>
mysql查询一个表的字段,添加或修改到另外一个表的数据
查看>>
数据库词典设计
查看>>
CL.exe的 /D 选项, Preprocessor Macro预处理器宏定义
查看>>
[Pytorch]Pytorch中tensor常用语法
查看>>
ZOJ 1008 Gnome Tetravex
查看>>
android从内部存储写入、安装apk提示解析包错误,或者提示Permission Denied,文件不可用解决办法...
查看>>