declare styleableandroid中如何在xml文件中增加属性

declare styleable  时间:2022-02-27  阅读:()

沉浸式状态栏实现为什么要用toolbar

首先使用 Toolbar 来代替ActionBar ,这样我们就能够把ActionBar嵌入到我们的View体系中,然后我们"禁用"系统的status bar,由 DrawerLayout 来处理status bar,最后抽屉部分往上移,或者裁剪掉status bar那一部分。   控制Status bar   在你的values-v21里面添加新的主题,并设置一下属性:   values-v21/themes.xml   <style name="AppTheme">   <item name="android:windowDrawsSystemBarBackgrounds">true</item>   <item name="android:statusBarColor">@android:color/transparent</item>   </style>   这里解释一下:   windowDrawsSystemBarBackgrounds ,将它设置为true,系统将在你的window里面绘制status bar,默认为 TRUE ,之所以要写出来是因为你的theme有可能是继承过来的,确保为true。(在这里小插曲一下,因调试时,总以为注释了这段代码就以为是false,程序员思维害苦了我。另外从命名来看,Android把它称为system bar,可能是为了与能被我们处理的status bar区分开而做的改变。)   statusBarColor 设置为透明是因为我们不再需要系统的status bar,因为我们无法控制它的位置,后面我们将交由 DrawerLayout 来处理。   使用DrawerLayout   首先,你的布局文件应该是和这个类似的:   <android.support.v4.widget.DrawerLayout   xmlns:android="url"   android:id="@+id/my_drawer_layout"   android:layout_width="match_parent"   android:layout_height="match_parent"   android:fitsSystemWindows="true">   <!-- Your normal content view -->   <LinearLayout   android:layout_width="match_parent"   android:layout_height="match_parent"   android:orientation="vertical">   <!-- We use a Toolbar so that our drawer can be displayed   in front of the action bar -->   <android.support.v7.widget.Toolbar   android:id="@+id/my_awesome_toolbar"   android:layout_height="wrap_content"   android:layout_width="match_parent"   android:minHeight="?attr/actionBarSize"   android:background="?attr/colorPrimary" />   <!-- The rest of your content view -->   </LinearLayout>   <!-- The navigation drawer -->   <ScrimInsetsFrameLayout xmlns:android="rul"   xmlns:app="url"   android:layout_width="304dp"   android:layout_height="match_parent"   android:layout_gravity="left"   android:background="@android:color/white"   android:elevation="10dp"   android:fitsSystemWindows="true"   app:insetForeground="#4000">   <!-- Your drawer content -->   </ScrimInsetsFrameLayout>   </android.support.v4.widget.DrawerLayout>   在这里布局里面我们用到了一个的开源类 ScrimInsetsFrameLayout ,它的主要作用就是利用 fitsSystemWindows 的回调方法 fitSystemWindows(Rect insets) 来获取status bar的大小,然后调整画布已达到去掉status bar的效果,所以我们需要在ScrimInsetsFrameLayout 下设置 fitsSystemWindows 为true。当然你也可以不使用这个类,而改用 layout_marginTop 属性来达到效果。   insetForeground 这个属性是ScrimInsetsFrameLayout自带的,表示插入区域的前景色,我们设置为带透明的黑色#4000。别忘了使用这个属性需要添加如下代码到attrs.xml里:   values/attrs.xml   <declare-styleable name="ScrimInsetsView">   <attr name="insetForeground" format="reference|color" />   </declare-styleable>   自此,我们已经实现了将DrawerLayout抽屉的那一部分显示在 Toolbar 和systembar(为了和下面的status bar区分,我们称为system bar)之间了,可是system bar的颜色被我们设置了透明,所以我们接下来要改变status bar的颜色。   改变Status bar的颜色   你可能已经注意到刚才的布局里面 DrawerLayout 的 fitsSystemWindows 属性设置了为true,这是因为我们要在代码里面使用了 DrawerLayout 设置status bar颜色的方法:   // 在这里我们获取了主题暗色,并设置了status bar的颜色   TypedValue typedValue = new TypedValue();   getTheme().resolveAttribute(R.attr.colorPrimaryDark, typedValue, true);   int color = typedValue.data;   // 注意setStatusBarBackgroundColor方法需要你将fitsSystemWindows设置为true才会生效   DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.my_drawer_layout);   drawerLayout.setStatusBarBackgroundColor(color);   使用ToolBar来代替ActionBar   在代码里面这样设置:   Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);   setSupportActionBar(toolbar);

android中如何在xml文件中增加属性

添加文件attrs.xml,位于resvalues目录下: 1 <?xml version="1.0" encoding="utf-8"?> 2 <resources> 3 <declare-styleable name="myView"> 4 <attr name="textColor" format="color"/> 5 <attr name="textSize" format="dimension"/> 6 </declare-styleable> 7 </resources>

A400互联37.8元/季,香港节点cn2,cmi线路云服务器,1核/1G/10M/300G

A400互联怎么样?A400互联是一家成立于2020年的商家,A400互联是云服务器网(yuntue.com)首次发布的云主机商家。本次A400互联给大家带来的是,全新上线的香港节点,cmi+cn2线路,全场香港产品7折优惠,优惠码0711,A400互联,只为给你提供更快,更稳,更实惠的套餐,香港节点上线cn2+cmi线路云服务器,37.8元/季/1H/1G/10M/300G,云上日子,你我共享。...

RangCloud19.8元/月,香港cn2云主机,美国西雅图高防云主机28元/月起

rangcloud怎么样?rangcloud是去年年初开办的国人商家,RangCloud是一家以销售NAT起步,后续逐渐开始拓展到VPS及云主机业务,目前有中国香港、美国西雅图、韩国NAT、广州移动、江门移动、镇江BGP、山东联通、山东BGP等机房。目前,RangCloud提供香港CN2线路云服务器,电信走CN2、联通移动直连,云主机采用PCle固态硬盘,19.8元/月起,支持建站使用;美国高防云...

licloud:$39/月,香港物理服务器,30M带宽,e3-1230v3/16G内存/1T硬盘

licloud官方消息:当前对香港机房的接近100台物理机(香港服务器)进行打折处理,30Mbps带宽,低至不到40美元/月,速度快,性价比高,跑绝大多数项目都是绰绰有余了。该款香港服务器自带启动、关闭、一键重装功能,正常工作日内30~60分钟交货(不包括非工作日)。 官方网站:https://licloud.io 特价香港物理服务器 CPU:e3-1230v2(4核心、8线程、3.3GH...

declare styleable为你推荐
在线编辑有没有能在手机端在线编辑文档的软件?一致性数据库系统中 数据的一致性指的是什么?微指数微指数的新浪微博官方应用-微指数php开发工具PHP开发工具IDE哪个好用,请推荐几个?谢谢apple以旧换新苹果以旧换新怎么换密码设置怎么设置开机密码?安卓模拟器哪个好用安卓模拟器哪个最好安卓模拟器哪个好用电脑上的手机模拟器有哪些?哪个更好一点?visio使用教程怎样使用visio画E-R图实数的定义实数的定义
已经备案域名 kdata godaddy续费优惠码 空间打开慢 好玩的桌面 免费ftp空间申请 电子邮件服务器 idc是什么 adroit 中国网通测速 如何建立邮箱 西安服务器托管 监控服务器 谷歌台湾 SmartAXMT800 日本小学生 vim 瓦工招聘 ddos攻击器 suspended翻译 更多