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>

轻云互联(19元)香港高防云服务器 ,美国云服务器

轻云互联成立于2018年的国人商家,广州轻云互联网络科技有限公司旗下品牌,主要从事VPS、虚拟主机等云计算产品业务,适合建站、新手上车的值得选择,香港三网直连(电信CN2GIA联通移动CN2直连);美国圣何塞(回程三网CN2GIA)线路,所有产品均采用KVM虚拟技术架构,高效售后保障,稳定多年,高性能可用,网络优质,为您的业务保驾护航。活动规则:用户购买任意全区域云服务器月付以上享受免费更换IP服...

CheapWindowsVPS$4.5/月,美国VPS/免费Windows系统/1Gbps不限流量/,可选美洲、欧洲、亚洲等8大机房

国外商家提供Windows系统的并不常见,CheapWindowsVPS 此次提供的 2 款 VPS 促销套餐,提供 5 折永久优惠码,优惠后月付 4.5 美元起,价格还是挺诱人的,VPS 不限流量,接入 1Gbps 带宽,8 个机房皆可选,其中洛杉矶机房还提供亚洲优化网络供选择,操作系统有 Windows 10 专业版、2012 R2、2016、Linux等。Cheap Windows VPS是...

新加坡云服务器 1核2Gg 46元/月 香港云服务器 1核2G 74元/月 LightNode

LightNode是一家成立于2002年,总部位于香港的VPS服务商。提供基于KVM虚拟化技术.支持CentOS、Ubuntu或者Windows等操作系统。公司名:厦门靠谱云股份有限公司官方网站:https://www.lightnode.com拥有高质量香港CN2 GIA与东南亚节点(河内、曼谷、迪拜等)。最低月付7.71美金,按时付费,可随时取消。灵活满足开发建站、游戏应用、外贸电商等需求。首...

declare styleable为你推荐
初始化磁盘win7系统如何磁盘初始化?apple以旧换新苹果手机可以以旧换新吗订单详情在淘宝上买东西,显示订单已发货,但是没有订单详情。可能有几种原因?scanf返回值何为函数的返回值,比如scanf()函数的返回值?密码设置怎么设置开机密码?实数的定义实数的定义rs485协议“485通信协议”是什么?赵锡成众生有罪,你我皆同谋。什么意思碰撞球两小球碰撞冲量怎么计算碰撞球碰撞分为哪几种,分别解释一下
xenvps 七牛优惠码 pccw kdata 流媒体服务器 php主机 网站保姆 新世界电讯 lighttpd ev证书 国外免费空间 mysql主机 创梦 天互数据 umax120 idc查询 网站在线扫描 vul 国外在线代理服务器 ledlamp 更多