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>

易探云2核2G5M仅330元/年起,国内挂机宝云服务器,独立ip

易探云怎么样?易探云是国内一家云计算服务商家,致力香港服务器、国内外服务器租用及托管等互联网业务,目前主要地区为运作香港BGP、香港CN2、广东、北京、深圳等地区。目前,易探云推出深圳或北京地区的适合挂机和建站的云服务器,国内挂机宝云服务器(可选深圳或北京地区),独立ip;2核2G5M挂机云服务器仅330元/年起!点击进入:易探云官方网站地址易探云国内挂机宝云服务器推荐:1、国内入门型挂机云服务器...

HostKvm四月优惠:VPS主机全场八折,香港/美国洛杉矶机房$5.2/月起

HostKvm是一家成立于2013年的国外主机服务商,主要提供基于KVM架构的VPS主机,可选数据中心包括日本、新加坡、韩国、美国、中国香港等多个地区机房,均为国内直连或优化线路,延迟较低,适合建站或者远程办公等。本月商家针对全场VPS主机提供8折优惠码,优惠后美国洛杉矶VPS月付5.2美元起。下面列出几款不同机房VPS主机产品配置信息。套餐:美国US-Plan0CPU:1cores内存:1GB硬...

Boomer.Host(年付3.5美)休斯敦便宜VPS

Boomer.Host是一家比较新的国外主机商,虽然LEB自述 we’re now more than 2 year old,商家提供虚拟主机和VPS,其中VPS主机基于OpenVZ架构,数据中心为美国得克萨斯州休斯敦。目前,商家在LET发了两款特别促销套餐,年付最低3.5美元起,特别提醒:低价低配,且必须年付,请务必自行斟酌确定需求再入手。下面列出几款促销套餐的配置信息。CPU:1core内存:...

declare styleable为你推荐
rbo在么?那个RBO出招表到底怎么回事 斩舰刀怎么用豆瓣fm电台豆瓣电台怎么听自己喜欢歌手的歌豆瓣fm电台虾米猜电台和豆瓣fm哪个好?密码设置怎么设置开机密码?密码设置怎么给电脑设置密码?高质量图片ps 合成图片,怎样才算高质量的?从那些方面判定照片的质量mapsource怎么用mapsource制作地球化学航迹图小蓝条戴尔系统开机动画里的小蓝条怎么去阶乘函数用函数求阶乘的C语言网站维护收费网页制作与维护,费用
个人域名备案 a5域名交易 花生壳域名贝锐 购买域名和空间 高防dns 5折 国外服务器 网站保姆 NetSpeeder 绍兴高防 卡巴斯基永久免费版 e蜗 徐正曦 169邮箱 重庆双线服务器托管 重庆电信服务器托管 贵阳电信 lamp是什么意思 带宽测试 杭州电信宽带 更多