首页 文章 精选 留言 我的

精选列表

搜索[教程],共10000篇文章
优秀的个人博客,低调大师

04-移动端开发教程-在线字体图标

在IE4开始微软就已经开始支持在线字体,不过没有流行起来,直到CSS3新增加了font-face模块,正式纳入了web开发的标准。也渐渐流行起来而且发掘了很多其他应用。 1. 为什么要用在线字体 问题 精灵图(雪碧图)用作背景的时候不能轻易的放大缩小。 低质量的位图在高清设备上放大后会有难看的锯齿,无法满足响应式页面的开发需求 在线字体带来的革命: 在线字体本质就是文字,但是也可是像图形的文字。节省了带宽(相比图片)字体文件大小也不大(一般几百k)。 在线字体本身是矢量的,放大缩小都不会失真 可以灵活的通过css来控制字体图标的大小、颜色、阴影等 可以方便的自定义字体图标 2. 在线字体 @font-face是CSS3中的一个模块,他主要是把自己定义的Web字体嵌入到你的网页中,允许我们不依赖操作系统的字体,做到全平台字体统一和定制。 语法规则: @font-face { font-family: <YourWebFontName>; src: <source> [<format>][,<source> [<format>]]*; [font-weight: <weight>]; [font-style: <style>]; } 取值说明: YourWebFontName:此值指的就是你自定义的字体名称,他将被引用到你的Web元素中的font-family。如“font-family:"YourWebFontName";” source:此值指的是你自定义的字体的存放路径,可以是相对路径也可以是绝路径; format:此值指的是你自定义的字体的格式,主要用来帮助浏览器识别,其值主要有以下几种类型:truetype,opentype,truetype-aat,embedded-opentype,avg等; weight和style:这两个值大家一定很熟悉,weight定义字体是否为粗体,style主要定义字体样式。 3.字体类型 不同的浏览器对字体格式支持是不一致的,以下是各种类型的字体的介绍。 TureTpe(.ttf)格式: .ttf字体是Windows和Mac的最常见的字体,是一种RAW格式,因此他不为网站优化,支持这种字体的浏览器有【IE9+,Firefox3.5+,Chrome4+,Safari3+,Opera10+,iOS Mobile Safari4.2+】; OpenType(.otf)格式: .otf字体被认为是一种原始的字体格式,其内置在TureType的基础上,所以也提供了更多的功能,支持这种字体的浏览器有【Firefox3.5+,Chrome4.0+,Safari3.1+,Opera10.0+,iOS Mobile Safari4.2+】; Web Open Font Format(.woff)格式: .woff字体是Web字体中最佳格式,他是一个开放的TrueType/OpenType的压缩版本,同时也支持元数据包的分离,支持这种字体的浏览器有【IE9+,Firefox3.5+,Chrome6+,Safari3.6+,Opera11.1+】; Embedded Open Type(.eot)格式: .eot字体是IE专用字体,可以从TrueType创建此格式字体,支持这种字体的浏览器有【IE4+】; SVG(.svg)格式: .svg字体是基于SVG字体渲染的一种格式,支持这种字体的浏览器有【Chrome4+,Safari3.1+,Opera10.0+,iOS Mobile Safari3.2+】。 这就意味着在@font-face中我们至少需要.woff,.eot两种格式字体,甚至还需要.svg等字体达到更多种浏览版本的支持。 4. 字体兼容写法 @font-face { font-family: 'YourWebFontName'; src: url('YourWebFontName.eot'); /* IE9 Compat Modes */ src: url('YourWebFontName.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */ url('YourWebFontName.woff') format('woff'), /* Modern Browsers */ url('YourWebFontName.ttf') format('truetype'), /* Safari, Android, iOS */ url('YourWebFontName.svg#YourWebFontName') format('svg'); /* Legacy iOS */ } h1 { font-family: 'YourWebFontName' } 4. bootstrap在线字体应用 第一种:直接应用bootstrap提供的样式类型 <!-- 引用bootstrap样式文件 --> <!-- 最新版本的 Bootstrap 核心 CSS 文件 --> <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> <div> <!-- 在需要字体图标的地方添加i标签,并添加图标样式类 --> <i class="glyphicon glyphicon-eur"></i> </div> 第二种:直接下载bootstrap压缩包。 下载地址:下载 解压后,把字体包fonts文件加载拷贝到项目的根目录下。 <style> /* 自定义在线字体,浏览器会自动下载下面的字体文件 */ @font-face { font-family: 'glyphicons'; src: url('./fonts/glyphicons-halflings-regular.eot'); /* IE9 Compat Modes */ src: url('./fonts/glyphicons-halflings-regular.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */ url('./fonts/glyphicons-halflings-regular.woff') format('woff'), /* Modern Browsers */ url('./fonts/glyphicons-halflings-regular.ttf') format('truetype'), /* Safari, Android, iOS */ url('./fonts/glyphicons-halflings-regular.svg#glyphicons') format('svg'); /* Legacy iOS */ } .hd-r { /* 设置字体类型 */ font-family: 'glyphicons','Microsoft YaHei',serif; } </style> <div class="hd-r">&#x2002; &#xe005;&#xe012;&#x2601;</div> 5. fontawesome在线字体应用 Font Awesome gives you scalable vector icons that can instantly be customized — size, color, drop shadow, and anything that can be done with the power of CSS. Font Awesome 提供了高可用性的矢量图标字体。它可以用强大的CSS自定义图标的大小、颜色、图标阴影等。 使用方法如下:(非常类似bootstrap) <link rel="stylesheet" href="./font-awesome-4.7.0/css/font-awesome.css"> <i class="fa fa-camera-retro"></i> <i class="fa fa-camera-retro fa-lg"></i> fa-lg <i class="fa fa-camera-retro fa-2x"></i> fa-2x <i class="fa fa-camera-retro fa-3x"></i> fa-3x <i class="fa fa-camera-retro fa-4x"></i> fa-4x <i class="fa fa-camera-retro fa-5x"></i> fa-5x <i class="fa fa-refresh fa-spin fa-fw" aria-hidden="true"></i> <span class="sr-only">Refreshing...</span> 6. 自定义字体在线工具 有很多可以直接在线编辑和上传自定义字体的工具和网站。其中:icomoon就是比较常用的一个在线制作字体的网站。有很多免费的字体可以用,而且可以在线编辑和上传。 此在线工具可以选择图标、增加图标、修改图标、移动图标、上传图标等操作,操作完成后选择要下载的图标然后选择右下角的生成字体,然后就可以下载字体了。 字体下载下来后,可以直接用它提供的字体文件和样式类型文件。 其他: 定制自已的字体图标库 http://iconfont.cn/ 联系老马 对应视频地址:https://chuanke.baidu.com/s5508922.html 老马qq: 515154084 老马微信:请扫码 扫码加老马微信

优秀的个人博客,低调大师

Android教程之如何使用自定义字体

要在其他平台实现自定义字体可谓是相当的麻烦,但是在Android平台就很简单了。 首先将自定义字体放到“assets”下面被实例化之后再使用,字体文件如下图所示。 在程序中通过如下方式实例化自定义字体: Typeface.createFromAsset(getContext().getAssets(),"fonts/samplefont.ttf"); 下面是Android默认字体和自定义字体的绘制效果: 源代码如下: packagecom.yarin.android.Typefaces; importandroid.app.Activity; importandroid.content.Context; importandroid.graphics.Canvas; importandroid.graphics.Color; importandroid.graphics.Paint; importandroid.graphics.Typeface; importandroid.os.Bundle; importandroid.view.View; publicclassTypefacesextendsActivity { /**Calledwhentheactivityisfirstcreated.*/ @Override publicvoidonCreate(BundlesavedInstanceState) { super.onCreate(savedInstanceState); setContentView(newSampleView(this)); } privatestaticclassSampleViewextendsView { privatePaintmPaint=newPaint(Paint.ANTI_ALIAS_FLAG); privateTypefacemFace; publicSampleView(Contextcontext) { super(context); //实例化自定义字体 mFace=Typeface.createFromAsset(getContext().getAssets(),"fonts/samplefont.ttf"); //设置字体大小 mPaint.setTextSize(32); } @OverrideprotectedvoidonDraw(Canvascanvas) { canvas.drawColor(Color.WHITE); //绘制默认字体 mPaint.setTypeface(null); canvas.drawText("Default:abcdefg",10,100,mPaint); //绘制自定义字体 mPaint.setTypeface(mFace); canvas.drawText("Custom:abcdefg",10,200,mPaint); } } } 好了,就这么简单就实现了自定义字体。 下面是两个非常有用的方法,在这里备份一下: //消除锯齿 paint.setFlags(Paint.ANTI_ALIAS_FLAG) //取得字符串宽度 paint.measureText() 本文转自 yarin 51CTO博客,原文链接:http://blog.51cto.com/yarin/380358,如需转载请自行联系原作者

优秀的个人博客,低调大师

vmware虚拟机安装CentOS7教程

centos是企业最常用的服务器系统之一,CentOS是免费的,所以用的企业也挺多,今天给大家分享怎么在自己电脑的虚拟机中安装CentOS-6.5,以便用来玩耍,没事的时候可以学学linux的一些知识。 1.下载CentOs安装镜像盘 下载地址:http://www.centoscn.com/CentosSoft/iso/2017/1119/9264.html 注:真正生产环境的oracle数据库一般是一整台服务器只用作数据库,不会安装其他应用,也不会安装xwindow图形界面,为了更好的模拟生产环境场景,这里选择了minimal版本的。 2.启动VMware Workstation,“文件”->“新建虚拟机” 3.选择“典型”,点击下一步 4.选择“稍后安装操作系统”,点击下一步 5.客户机操作系统选择 linux,版本选择 centos64位,点击下一步 6.填写虚拟机名称,选择本地文件夹,存放虚拟机文件,点击下一步 7.最大磁盘大小,填写“50”GB,下面的默认,点击下一步 8.点击“完成”,完成虚拟机的新建,左边就看到了刚新建好的虚拟机了 9.单击右键,设置虚拟机 10.内存设为2G 11.CD/DVD,选择“使用ISO映像文件”,选择刚才下载的Centos镜像文件 12.网络适配器选择桥接模式,点击确认,完成虚拟机的设置 13.点击“开启此虚拟机” 14.点击确定或者取消 15.鼠标点进去,按回车 16.稍微等待一会 17.选择语言,点击Continue 18.选择键盘,Done 19.选择安装的目的地,Done 20.点击Begin Installation 21.点击Root Password输入root用户密码,点“Done”(超级管理员root,拥有系统最高权限)注:root密码要切记,设置真正的生产环境这个密码适当设置复杂写,数组,字母,标点组合字符串,当然,我这是自己测试装系统的,输入了个比较简单的密码“Uidp01” 22.等待安装 23.点击Reboot重新启动 24.等待一会,出现输入用户账号密码界面,输入账号密码 25.成功登录 说明:这个系统是精简版minimal版本,很多软件包都是没有安装的。 可爱博主:AlanLee

优秀的个人博客,低调大师

Windows 2008从入门到精通系列教程(二)

了解了Windows 2008的十大新功能,我相信大家已经迫不及待的想要去安装一个Windows 2008服务器来试用了。建议朋友们可以在虚拟机里面安装Windows 2008 R2,我这里使用的是VM。 Windows 2008 R2大致有四种安装方式,这里将一一讲解不同的安装方式。 1.升级安装:Windows 2008 R2的升级安装是针对Windows 2003的,下列Windows版本不能升级到2008 R2: Windows 95, Windows 98, Windows ME, Windows XP, Windows Vista 和 Windows 7 Windows NT Server 4.0, Windows 2000 Server, Windows Server 2003 RTM, Windows Server 2003 SP1, Windows Server 2003 Web和Windows Server 2008 R2 Beta Windows Server 2003 IA64, Windows Server 2003 x64, Windows Server 2008 IA64 不支持跨架构进行升级(例如,X86不能被升级到X64) 不支持跨语言进行升级(例如,英文版不能被升级成中文版) 不支持跨版本进行升级(例如,Windows Server 2008 Foundation不能被升级到Windows Server 2008 数据中心版) 支持的升级安装方式 从Windows Server 2003 (SP2, R2) 升级到Windows Server 2008 R2 数据中心版 数据中心版 企业版 企业版和数据中心版 标准版标准版和企业版 从Windows Server 2008 (RTM-SP1, SP2) 升级到Windows Server 2008 R2 数据中心版 数据中心版 数据中心版核心 数据中心版核心 企业版 企业版和数据中心版 企业版核心企业版核心和数据中心版核心 Foundation (SP2) 标准版 标准版 标准版和企业版 标准版核心标准版核心和企业版核心 Web版 Web版和标准版 Web版核心 Web版核心和标准版核心 从Windows Server 2008 (RC,IDS) 升级到Windows Server 2008 R2 数据中心版 数据中心版 数据中心版核心数据中心版核心 企业版 企业版和数据中心版 企业版核心 企业版核心和数据中心版核心 Foundation (SP2) 标准版 标准版 标准版和企业版 标准版核心 标准版核心和企业版核心 Web版Web版和标准版 Web版核心Web版核心和标准版核心 2.全新安装:即在一个全新的服务器上安装Windows Server 2008R2. 3.远程安装,此种安装模式用于批量安装windows server 2008R2,可以使用WDS或者其它方法安装,在后面的章节中会介绍。 4.Server Core安装,只安装核心的模块,Server Core模式不具有图形界面,所有的操作都是通过命令实现,主要用于安装DHCP,DNS等服务,稍后会介绍。 5.安装一个Windows Server 2008R2的步骤如下:限于篇幅,本文只简单将安装过程的截图放在下面。 此处若选择升级则为升级安装,如果选择自定义,其实就是全新的安装了。 这里的密码必须包含数字,大写字母,小写字母,特殊符号中的三种组合。 总结:Windows Server 2008必然成为以后的微软操作系统的趋势,因此,大家必须学会不同的方式安装Windows Server 2008系统。 本文转自 ningxiang00 51CTO博客,原文链接:http://blog.51cto.com/andygao/471569,如需转载请自行联系原作者

优秀的个人博客,低调大师

Puppet安装与配置简介(附视频教程)

Puppet是一种Linux平台的集中配置管理系统,他可管理配置文件、用户、cron任务、软件包、系统服务等。puppet把这些系统实体称之为资源,puppet采用C/S星状的结构,所有的客户端和一个或几个服务器交互。每个客户端周期的(默认半个小时)向服务器发送请求,获得其最新的配置信息,保证和该配置信息同步。每个puppet客户端每半小时(可以设置)连接一次服务器端,下载最新的配置文件,并且严格按照配置文件来配置服务器.配置完成以后,puppet客户端可以反馈给服务器端一个消息.以下视频已Suse企业版本为基础为大家展示如何安装与配置Puppet管理系统。今后我在向大家介绍如何Puppet+Cobber实现自动化安装Openstack. 本文转自 李晨光 51CTO博客,原文链接:http://blog.51cto.com/chenguang/999352 ,如需转载请自行联系原作者

优秀的个人博客,低调大师

Android修改状态栏颜色全方位教程

关键字:状态栏着色 透明状态栏 沉浸式 白底黑字 Github Demo:https://github.com/imflyn/Eyes 参考文章:Android-transulcent-status-barAndroid 6.0状态栏使用灰色文字和图标Android系统更改状态栏字体颜色 在谷歌官方的material设计文档中定义了新的状态栏设计。https://material.io/guidelines/layout/structure.html#structure-system-bars 默认情况下,状态栏的颜色是黑色的。同时状态栏颜色也可以半透明或是指定任意一种颜色。 1.改变颜色后的状态栏 2.半透明状态栏 3.黑色状态栏 黑色icon或文字的状态栏 接下来讲一下具体实现 一.改变状态栏颜色 4.4-5.0的处理: 4.4-5.0还没有API可以直接修改状态栏颜色,所以必须先将状态栏设置为透明,然后在布局中添加一个背景为期望色值的View来作为状态栏的填充。 static void setStatusBarColor(Activity activity, int statusColor) { Window window = activity.getWindow(); //设置Window为全透明 window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); ViewGroup mContentView = (ViewGroup) window.findViewById(Window.ID_ANDROID_CONTENT); //获取父布局 View mContentChild = mContentView.getChildAt(0); //获取状态栏高度 int statusBarHeight = getStatusBarHeight(activity); //如果已经存在假状态栏则移除,防止重复添加 removeFakeStatusBarViewIfExist(activity); //添加一个View来作为状态栏的填充 addFakeStatusBarView(activity, statusColor, statusBarHeight); //设置子控件到状态栏的间距 addMarginTopToContentChild(mContentChild, statusBarHeight); //不预留系统栏位置 if (mContentChild != null) { ViewCompat.setFitsSystemWindows(mContentChild, false); } //如果在Activity中使用了ActionBar则需要再将布局与状态栏的高度跳高一个ActionBar的高度,否则内容会被ActionBar遮挡 int action_bar_id = activity.getResources().getIdentifier("action_bar", "id", activity.getPackageName()); View view = activity.findViewById(action_bar_id); if (view != null) { TypedValue typedValue = new TypedValue(); if (activity.getTheme().resolveAttribute(R.attr.actionBarSize, typedValue, true)) { int actionBarHeight = TypedValue.complexToDimensionPixelSize(typedValue.data, activity.getResources().getDisplayMetrics()); setContentTopPadding(activity, actionBarHeight); } } } private static void removeFakeStatusBarViewIfExist(Activity activity) { Window window = activity.getWindow(); ViewGroup mDecorView = (ViewGroup) window.getDecorView(); View fakeView = mDecorView.findViewWithTag(TAG_FAKE_STATUS_BAR_VIEW); if (fakeView != null) { mDecorView.removeView(fakeView); } } private static View addFakeStatusBarView(Activity activity, int statusBarColor, int statusBarHeight) { Window window = activity.getWindow(); ViewGroup mDecorView = (ViewGroup) window.getDecorView(); View mStatusBarView = new View(activity); FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, statusBarHeight); layoutParams.gravity = Gravity.TOP; mStatusBarView.setLayoutParams(layoutParams); mStatusBarView.setBackgroundColor(statusBarColor); mStatusBarView.setTag(TAG_FAKE_STATUS_BAR_VIEW); mDecorView.addView(mStatusBarView); return mStatusBarView; } private static void addMarginTopToContentChild(View mContentChild, int statusBarHeight) { if (mContentChild == null) { return; } if (!TAG_MARGIN_ADDED.equals(mContentChild.getTag())) { FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mContentChild.getLayoutParams(); lp.topMargin += statusBarHeight; mContentChild.setLayoutParams(lp); mContentChild.setTag(TAG_MARGIN_ADDED); } } static void setContentTopPadding(Activity activity, int padding) { ViewGroup mContentView = (ViewGroup) activity.getWindow().findViewById(Window.ID_ANDROID_CONTENT); mContentView.setPadding(0, padding, 0, 0); } Android5.0以上的处理: static void setStatusBarColor(Activity activity, int statusColor) { Window window = activity.getWindow(); //取消状态栏透明 window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); //添加Flag把状态栏设为可绘制模式 window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); //设置状态栏颜色 window.setStatusBarColor(statusColor); //设置系统状态栏处于可见状态 window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE); //让view不根据系统窗口来调整自己的布局 ViewGroup mContentView = (ViewGroup) window.findViewById(Window.ID_ANDROID_CONTENT); View mChildView = mContentView.getChildAt(0); if (mChildView != null) { ViewCompat.setFitsSystemWindows(mChildView, false); ViewCompat.requestApplyInsets(mChildView); } } 二.透明状态栏 4.4-5.0的处理: static void translucentStatusBar(Activity activity) { Window window = activity.getWindow(); //设置Window为透明 window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); ViewGroup mContentView = (ViewGroup) activity.findViewById(Window.ID_ANDROID_CONTENT); View mContentChild = mContentView.getChildAt(0); //移除已经存在假状态栏则,并且取消它的Margin间距 removeFakeStatusBarViewIfExist(activity); removeMarginTopOfContentChild(mContentChild, getStatusBarHeight(activity)); if (mContentChild != null) { //fitsSystemWindow 为 false, 不预留系统栏位置. ViewCompat.setFitsSystemWindows(mContentChild, false); } } 5.0以上的处理: static void translucentStatusBar(Activity activity, boolean hideStatusBarBackground) { Window window = activity.getWindow(); //添加Flag把状态栏设为可绘制模式 window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); if (hideStatusBarBackground) { //如果为全透明模式,取消设置Window半透明的Flag window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); //设置状态栏为透明 window.setStatusBarColor(Color.TRANSPARENT); //设置window的状态栏不可见 window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); } else { //如果为半透明模式,添加设置Window半透明的Flag window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); //设置系统状态栏处于可见状态 window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE); } //view不根据系统窗口来调整自己的布局 ViewGroup mContentView = (ViewGroup) window.findViewById(Window.ID_ANDROID_CONTENT); View mChildView = mContentView.getChildAt(0); if (mChildView != null) { ViewCompat.setFitsSystemWindows(mChildView, false); ViewCompat.requestApplyInsets(mChildView); } } 三.使用CollapsingToolbarLayout使ToolBar具有折叠效果 类似图片中的效果 首先是XML布局: <?xml version="1.0" encoding="utf-8"?> <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true"> <android.support.design.widget.AppBarLayout android:id="@+id/appbar" android:layout_width="match_parent" android:layout_height="256dp" android:fitsSystemWindows="true" android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> <android.support.design.widget.CollapsingToolbarLayout android:id="@+id/collapsing_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" app:contentScrim="@color/colorPrimary" app:expandedTitleMarginEnd="64dp" app:expandedTitleMarginStart="48dp" app:layout_scrollFlags="scroll|exitUntilCollapsed" app:statusBarScrim="@color/colorPrimary"> <ImageView android:id="@+id/image" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" android:scaleType="centerCrop" android:src="@drawable/timg" app:layout_collapseMode="parallax" /> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" app:layout_collapseMode="pin" app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> </android.support.design.widget.CollapsingToolbarLayout> </android.support.design.widget.AppBarLayout> <android.support.v4.widget.NestedScrollView android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:paddingTop="24dp"> <android.support.v7.widget.CardView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="16dip"> <TextView android:layout_width="match_parent" android:layout_height="240dip" android:text="A" android:textAppearance="@style/TextAppearance.AppCompat.Title" /> </android.support.v7.widget.CardView> <android.support.v7.widget.CardView android:layout_width="match_parent" android:layout_height="240dip" android:layout_margin="16dip"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="B" android:textAppearance="@style/TextAppearance.AppCompat.Title" /> </android.support.v7.widget.CardView> <android.support.v7.widget.CardView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="16dip"> <TextView android:layout_width="match_parent" android:layout_height="240dip" android:text="C" android:textAppearance="@style/TextAppearance.AppCompat.Title" /> </android.support.v7.widget.CardView> <android.support.v7.widget.CardView android:layout_width="match_parent" android:layout_height="240dip" android:layout_margin="16dip"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="D" android:textAppearance="@style/TextAppearance.AppCompat.Title" /> </android.support.v7.widget.CardView> </LinearLayout> </android.support.v4.widget.NestedScrollView> </android.support.design.widget.CoordinatorLayout> 4.4-5.0的处理: static void setStatusBarColorForCollapsingToolbar(Activity activity, final AppBarLayout appBarLayout, final CollapsingToolbarLayout collapsingToolbarLayout, Toolbar toolbar, int statusColor) { Window window = activity.getWindow(); //设置Window为全透明 window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); ViewGroup mContentView = (ViewGroup) window.findViewById(Window.ID_ANDROID_CONTENT); //AppBarLayout,CollapsingToolbarLayout,ToolBar,ImageView的fitsSystemWindow统一改为false, 不预留系统栏位置. View mContentChild = mContentView.getChildAt(0); mContentChild.setFitsSystemWindows(false); ((View) appBarLayout.getParent()).setFitsSystemWindows(false); appBarLayout.setFitsSystemWindows(false); collapsingToolbarLayout.setFitsSystemWindows(false); collapsingToolbarLayout.getChildAt(0).setFitsSystemWindows(false); toolbar.setFitsSystemWindows(false); //为Toolbar添加一个状态栏的高度, 同时为Toolbar添加paddingTop,使Toolbar覆盖状态栏,ToolBar的title可以正常显示. if (toolbar.getTag() == null) { CollapsingToolbarLayout.LayoutParams lp = (CollapsingToolbarLayout.LayoutParams) toolbar.getLayoutParams(); int statusBarHeight = getStatusBarHeight(activity); lp.height += statusBarHeight; toolbar.setLayoutParams(lp); toolbar.setPadding(toolbar.getPaddingLeft(), toolbar.getPaddingTop() + statusBarHeight, toolbar.getPaddingRight(), toolbar.getPaddingBottom()); toolbar.setTag(true); } //移除已经存在假状态栏则,并且取消它的Margin间距 int statusBarHeight = getStatusBarHeight(activity); removeFakeStatusBarViewIfExist(activity); removeMarginTopOfContentChild(mContentChild, statusBarHeight); //添加一个View来作为状态栏的填充 final View statusView = addFakeStatusBarView(activity, statusColor, statusBarHeight); CoordinatorLayout.Behavior behavior = ((CoordinatorLayout.LayoutParams) appBarLayout.getLayoutParams()).getBehavior(); if (behavior != null && behavior instanceof AppBarLayout.Behavior) { int verticalOffset = ((AppBarLayout.Behavior) behavior).getTopAndBottomOffset(); if (Math.abs(verticalOffset) > appBarLayout.getHeight() - collapsingToolbarLayout.getScrimVisibleHeightTrigger()) { statusView.setAlpha(1f); } else { statusView.setAlpha(0f); } } else { statusView.setAlpha(0f); } appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() { @Override public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) { if (Math.abs(verticalOffset) > appBarLayout.getHeight() - collapsingToolbarLayout.getScrimVisibleHeightTrigger()) { //toolbar被折叠时显示状态栏 if (statusView.getAlpha() == 0) { statusView.animate().cancel(); statusView.animate().alpha(1f).setDuration(collapsingToolbarLayout.getScrimAnimationDuration()).start(); } } else { //toolbar展开时显示状态栏 if (statusView.getAlpha() == 1) { statusView.animate().cancel(); statusView.animate().alpha(0f).setDuration(collapsingToolbarLayout.getScrimAnimationDuration()).start(); } } } }); } 5.0以上的处理: static void setStatusBarColorForCollapsingToolbar(final Activity activity, final AppBarLayout appBarLayout, final CollapsingToolbarLayout collapsingToolbarLayout, Toolbar toolbar, final int statusColor) { final Window window = activity.getWindow(); //取消设置Window半透明的Flag window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); ////添加Flag把状态栏设为可绘制模式 window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); //设置状态栏为透明 window.setStatusBarColor(Color.TRANSPARENT); //设置系统状态栏处于可见状态 window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE); //通过OnApplyWindowInsetsListener()使Layout在绘制过程中将View向下偏移了,使collapsingToolbarLayout可以占据状态栏 ViewCompat.setOnApplyWindowInsetsListener(collapsingToolbarLayout, new OnApplyWindowInsetsListener() { @Override public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) { return insets; } }); ViewGroup mContentView = (ViewGroup) window.findViewById(Window.ID_ANDROID_CONTENT); View mChildView = mContentView.getChildAt(0); //view不根据系统窗口来调整自己的布局 if (mChildView != null) { ViewCompat.setFitsSystemWindows(mChildView, false); ViewCompat.requestApplyInsets(mChildView); } ((View) appBarLayout.getParent()).setFitsSystemWindows(false); appBarLayout.setFitsSystemWindows(false); collapsingToolbarLayout.setFitsSystemWindows(false); collapsingToolbarLayout.getChildAt(0).setFitsSystemWindows(false); //设置状态栏的颜色 collapsingToolbarLayout.setStatusBarScrimColor(statusColor); toolbar.setFitsSystemWindows(false); //为Toolbar添加一个状态栏的高度, 同时为Toolbar添加paddingTop,使Toolbar覆盖状态栏,ToolBar的title可以正常显示. if (toolbar.getTag() == null) { CollapsingToolbarLayout.LayoutParams lp = (CollapsingToolbarLayout.LayoutParams) toolbar.getLayoutParams(); int statusBarHeight = getStatusBarHeight(activity); lp.height += statusBarHeight; toolbar.setLayoutParams(lp); toolbar.setPadding(toolbar.getPaddingLeft(), toolbar.getPaddingTop() + statusBarHeight, toolbar.getPaddingRight(), toolbar.getPaddingBottom()); toolbar.setTag(true); } appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() { private final static int EXPANDED = 0; private final static int COLLAPSED = 1; private int appBarLayoutState; @Override public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) { //toolbar被折叠时显示状态栏 if (Math.abs(verticalOffset) > collapsingToolbarLayout.getScrimVisibleHeightTrigger()) { if (appBarLayoutState != COLLAPSED) { appBarLayoutState = COLLAPSED;//修改状态标记为折叠 setStatusBarColor(activity, statusColor); } } else { //toolbar显示时同时显示状态栏 if (appBarLayoutState != EXPANDED) { appBarLayoutState = EXPANDED;//修改状态标记为展开 translucentStatusBar(activity, true); } } } }); } 四.更改状态栏字体颜色 在Android 6.0的Api中提供了SYSTEM_UI_FLAG_LIGHT_STATUS_BAR这么一个常量,可以使状态栏文字设置为黑色,但对6.0以下是不起作用的。 小米和魅族的手机也可以达到这个效果,要做一些特殊的处理。可以参考小米和魅族的开发者文档。 Flyme沉浸式状态栏 MIUI 6 沉浸式状态栏调用方法 MIUI 9「状态栏黑色字符」实现方法变更通知 public static void setStatusBarLightMode(Activity activity, int color) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { //判断是否为小米或魅族手机,如果是则将状态栏文字改为黑色 if (MIUISetStatusBarLightMode(activity, true) || FlymeSetStatusBarLightMode(activity, true)) { //设置状态栏为指定颜色 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {//5.0 activity.getWindow().setStatusBarColor(color); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {//4.4 //调用修改状态栏颜色的方法 setStatusBarColor(activity, color); } } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { //如果是6.0以上将状态栏文字改为黑色,并设置状态栏颜色 activity.getWindow().setBackgroundDrawableResource(android.R.color.transparent); activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); activity.getWindow().setStatusBarColor(color); //fitsSystemWindow 为 false, 不预留系统栏位置. ViewGroup mContentView = (ViewGroup) activity.getWindow().findViewById(Window.ID_ANDROID_CONTENT); View mChildView = mContentView.getChildAt(0); if (mChildView != null) { ViewCompat.setFitsSystemWindows(mChildView, true); ViewCompat.requestApplyInsets(mChildView); } } } } 小米MiUi修改状态栏方法 static boolean MIUISetStatusBarLightMode(Activity activity, boolean darkmode) { boolean result = false; Class<? extends Window> clazz = activity.getWindow().getClass(); try { int darkModeFlag = 0; Class<?> layoutParams = Class.forName("android.view.MiuiWindowManager$LayoutParams"); Field field = layoutParams.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE"); darkModeFlag = field.getInt(layoutParams); Method extraFlagField = clazz.getMethod("setExtraFlags", int.class, int.class); extraFlagField.invoke(activity.getWindow(), darkmode ? darkModeFlag : 0, darkModeFlag); result = true; } catch (Exception e) { e.printStackTrace(); } return result; } 如果是MIUI9的系统还需要加上这段代码 Window window = getWindow(); window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); Flyme修改状态栏方法 static boolean FlymeSetStatusBarLightMode(Activity activity, boolean darkmode) { boolean result = false; try { WindowManager.LayoutParams lp = activity.getWindow().getAttributes(); Field darkFlag = WindowManager.LayoutParams.class .getDeclaredField("MEIZU_FLAG_DARK_STATUS_BAR_ICON"); Field meizuFlags = WindowManager.LayoutParams.class .getDeclaredField("meizuFlags"); darkFlag.setAccessible(true); meizuFlags.setAccessible(true); int bit = darkFlag.getInt(null); int value = meizuFlags.getInt(lp); if (darkmode) { value |= bit; } else { value &= ~bit; } meizuFlags.setInt(lp, value); activity.getWindow().setAttributes(lp); result = true; } catch (Exception e) { e.printStackTrace(); } return result; } 结语: 更详细的参考Demo在github中,如果有错误也希望大家能够指出。 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。 本文转自 一点点征服 博客园博客,原文链接:http://www.cnblogs.com/ldq2016/p/8353190.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

Android中的GPS应用开发入门教程

】LBS(Location Based Services)直译的话就是基于地理位置的服务,这里面至少有两层意思,第一要能轻易的获取当前的地理位置,譬如经纬度海拔等,另一个就是在当前位置的基础上提供增值服务,譬如找附近的加油站、餐馆、酒店等。这里面的第一步:获取用户当前位置,我们就可以用Android的GPS定位服务来得到。Android提供了基于网络的定位服务和基于卫星的定位服务两种。在设置->位置和安全设置里面的前三项就是,最后一个增强型GPS是为了辅助快速找卫星的。 那么我们现在就写一个简单的程序来实现获取当前位置的功能。 1、新建项目Lesson26_GPSLocation 2、MainActivity.java的代码如下: package basic.android.lesson26; import android.app.Activity; import android.content.Context; import android.location.Criteria; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.TextView; public class MainActivity extends Activity { TextView tv1; Location location; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); // 定义UI组件 Button b1 = (Button) findViewById(R.id.button1); tv1 = (TextView) findViewById(R.id.textView1); // 获取LocationManager对象 LocationManager lm = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); // 定义Criteria对象 Criteria criteria = new Criteria(); // 设置定位精确度 Criteria.ACCURACY_COARSE 比较粗略, Criteria.ACCURACY_FINE则比较精细 criteria.setAccuracy(Criteria.ACCURACY_FINE); // 设置是否需要海拔信息 Altitude criteria.setAltitudeRequired( true ); // 设置是否需要方位信息 Bearing criteria.setBearingRequired( true ); // 设置是否允许运营商收费 criteria.setCostAllowed( true ); // 设置对电源的需求 criteria.setPowerRequirement(Criteria.POWER_LOW); // 获取GPS信息提供者 String bestProvider = lm.getBestProvider(criteria, true ); Log .i( " yao " , " bestProvider = " + bestProvider); // 获取定位信息 location = lm.getLastKnownLocation(bestProvider); // 给按钮绑定点击监听器 b1.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { updateLocation(location); } }); // 位置监听器 LocationListener locationListener = new LocationListener() { // 当位置改变时触发 @Override public void onLocationChanged(Location location) { Log .i( " yao " , location.toString()); updateLocation(location); } // Provider失效时触发 @Override public void onProviderDisabled( String arg0) { Log .i( " yao " , arg0); } // Provider可用时触发 @Override public void onProviderEnabled( String arg0) { Log .i( " yao " , arg0); } // Provider状态改变时触发 @Override public void onStatusChanged( String arg0, int arg1, Bundle arg2) { Log .i( " yao " , " onStatusChanged " ); } }; // 500毫秒更新一次,忽略位置变化 lm.requestLocationUpdates(bestProvider, 500 , 0 , locationListener); } // 更新位置信息 private void updateLocation(Location location) { if (location ! = null ) { tv1.setText( " 定位对象信息如下: " + location.toString() + " \n\t其中经度: " + location.getLongitude() + " \n\t其中纬度: " + location.getLatitude()); } else { Log .i( " yao " , " 没有获取到定位对象Location " ); } } } 3、main.xml我就不贴代码了,就一个按钮和一个文本框,等一下看看截图就会明白。 4、要在AndroidManifest.xml中加入权限才行: < ! -- 粗略定位授权 --> < uses - permission = "" android:name = " android.permission.ACCESS_COARSE_LOCATION " ></ uses > < ! -- 精细定位授权 --> < uses - permission = "" android:name = " android.permission.ACCESS_FINE_LOCATION " ></ uses > < ! -- 模拟定位授权 --> < uses - permission = "" android:name = " android.permission.ACCESS_MOCK_LOCATION " ></ uses > < ! -- 网络访问授权 --> < uses - permission = "" android:name = " android.permission.INTERNET " ></ uses > 5、在真机上编译运行程序,查看结果: 这里要说明一下,我在模拟器上提交模拟器数据没成功,在真机上测试也不是很顺利,一和硬件有关就总会出一些莫名其妙的错误…… 本文转自 wws5201985 51CTO博客,原文链接:http://blog.51cto.com/wws5201985/736037,如需转载请自行联系原作者

资源下载

更多资源
优质分享App

优质分享App

近一个月的开发和优化,本站点的第一个app全新上线。该app采用极致压缩,本体才4.36MB。系统里面做了大量数据访问、缓存优化。方便用户在手机上查看文章。后续会推出HarmonyOS的适配版本。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

用户登录
用户注册
修改密码
忘记密码