Android自定义标题栏

getWindow().setFeatureInit最好在setContentView之后

第二步,就是写好自己的布局文件,实现标题栏的自定义。

不过我们会遇到一些问题,就是标题栏的高度不能自定义~下面就是解决办法~

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

下面,我们看一下android title标题栏 在源码 framework中的XML文件

screen_custom_title.xml

<LinearLayout android:orientation=“vertical” android:fitsSystemWindows=“true”>

  1. <FrameLayout android:id=“@android:id/title_container”

  2. android:layout_width=“match_parent”

  3. android:layout_height=“?android:attr/windowTitleSize”

  4. style=“?android:attr/windowTitleBackgroundStyle”>

  5. </FrameLayout>

  6. <FrameLayout android:id=“@android:id/content”

  7. android:layout_width=“match_parent”

  8. android:layout_height=“0dip”

  9. android:layout_weight=“1”

  10. android:foregroundGravity=“fill_horizontal|top”

  11. android:foreground=“?android:attr/windowContentOverlay”/>

  12. </LinearLayout>

screen_title.xml

<LinearLayout android:orientation=“vertical” android:fitsSystemWindows=“true”>

  1. <FrameLayout android:layout_width=“match_parent”

  2. android:layout_height=“?android:attr/windowTitleSize”

  3. style=“?android:attr/windowTitleBackgroundStyle”>

  4. <TextView android:id=“@android:id/title”

  5. style=“?android:attr/windowTitleStyle”

  6. android:background=“@null”

  7. android:fadingEdge=“horizontal”

  8. android:gravity=“center_vertical”

  9. android:layout_width=“match_parent”

  10. android:layout_height=“match_parent”/>

  11. </FrameLayout>

  12. <FrameLayout android:id=“@android:id/content”

  13. android:layout_width=“match_parent”

  14. android:layout_height=“0dip”

  15. android:layout_weight=“1”

  16. android:foregroundGravity=“fill_horizontal|top”

  17. android:foreground=“?android:attr/windowContentOverlay”/>

  18. </LinearLayout>

既然是自定义标题,那我们就看screen_custom_title.xml,里面有一个title_container和一个content,组合成了标题栏,我们自定义标题所给出的view,都被content作为子view了,影响不了那个title_container和content,所以,任你怎么弄,它该留白的还是留白,你没招。

看title_container有个style是这样的:

style=“?android:attr/windowTitleBackgroundStyle”

content的foreground是这样的android:foreground=“?android:attr/windowContentOverlay”

我们可以自己写一个style

<resources xmlns:android=“http://schemas.android.com/apk/res/android”>

作者2013年从java开发,转做Android开发,在小厂待过,也去过华为,OPPO等大厂待过,18年四月份进了阿里一直到现在。

参与过不少面试,也当面试官 面试过很多人。深知大多数初中级Android工程师,想要提升技能,往往是自己摸索成长,不成体系的学习效果低效漫长,而且极易碰到天花板技术停滞不前!

我整理了一份阿里P7级别的最系统的Android开发主流技术,特别适合有3-5年以上经验的小伙伴深入学习提升。

主要包括阿里,以及字节跳动,腾讯,华为,小米,等一线互联网公司主流架构技术。如果你想深入系统学习Android开发,成为一名合格的高级工程师,可以收藏一下这些Android进阶技术选型

我搜集整理过这几年阿里,以及腾讯,字节跳动,华为,小米等公司的面试题,把面试的要求和技术点梳理成一份大而全的“ Android架构师”面试 Xmind(实际上比预期多花了不少精力),包含知识脉络 + 分支细节。

Java语言与原理;
大厂,小厂。Android面试先看你熟不熟悉Java语言

高级UI与自定义view;
自定义view,Android开发的基本功。

性能调优;
数据结构算法,设计模式。都是这里面的关键基础和重点需要熟练的。

NDK开发;
未来的方向,高薪必会。

前沿技术;
组件化,热升级,热修复,框架设计

网上学习 Android的资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。希望这份系统化的技术体系对大家有一个方向参考。

我在搭建这些技术框架的时候,还整理了系统的高级进阶教程,会比自己碎片化学习效果强太多,CodeChina上可见;

当然,想要深入学习并掌握这些能力,并不简单。关于如何学习,做程序员这一行什么工作强度大家都懂,但是不管工作多忙,每周也要雷打不动的抽出 2 小时用来学习。

不出半年,你就能看出变化!
《Android学习笔记总结+移动架构视频+大厂面试真题+项目实战源码》点击传送门,即可获取!

当然,想要深入学习并掌握这些能力,并不简单。关于如何学习,做程序员这一行什么工作强度大家都懂,但是不管工作多忙,每周也要雷打不动的抽出 2 小时用来学习。

不出半年,你就能看出变化!
《Android学习笔记总结+移动架构视频+大厂面试真题+项目实战源码》点击传送门,即可获取!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值