摘要: 高斯模糊 Blurry Android图像处理 - 高斯模糊的原理及实现 // 源码 https://github.com/wasabeef/Blurry compile 'jp.wasabeef:blurry:4.0.1' 动态权限管理 XXPermissions 一句代码搞定权限请求,从未如此简 阅读全文
posted @ 2022-09-21 09:48 似水流云 阅读(167) 评论(0) 推荐(0) 编辑
摘要: 1.获取应用软件版本private PackageManager pm ; /** * 获取应用软件版本 * @return */ private String getAppVersion(){ pm = getPackageManager(); try { PackageInfo pinfo = pm.getPackageInfo("com.math.client", 0); String version = pinfo.versionName; retu... 阅读全文
posted @ 2013-05-07 18:31 似水流云 阅读(292) 评论(0) 推荐(0) 编辑

今天和视觉调样式的时候,发现一个问题,我们代码中经常使用fontFamily的样式,比如:

  <TextView
            android:id="@+id/name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/dip12"
            android:text="小粗体样式"
            android:textColor="@color/color_333333"
            android:textSize="@dimen/dip12"
            android:fontFamily="sans-serif-medium" />
//设置sans-serif-medium样式

但是如果我不是通过xml设置样式,而是想在自定义View中设置这种样式该怎么做呢?百度了一下,竟然没有找到相关的文章,真想给差评啊!那就只能靠自己了。

一、查看fontFamily属性的定义

该属性定义在系统的attrs.xml中,既然定义了一种属性,那么代码中一定会获取这个属性值。

 <!-- Default font family. -->
    <attr name="fontFamily" format="string" />

二、查看TextView源代码中如何使用的

首先获取属性值赋值给一个内部类TextAppearanceAttributes,该类专门存储相关属性值。赋值给了mFontFamily

 case com.android.internal.R.styleable.TextAppearance_fontFamily:
                    if (!context.isRestricted() && context.canLoadUnsafeResources()) {
                        try {
                            attributes.mFontTypeface = appearance.getFont(attr);
                        } catch (UnsupportedOperationException | Resources.NotFoundException e) {
                            // Expected if it is not a font resource.
                        }
                    }
                    if (attributes.mFontTypeface == null) {
                        attributes.mFontFamily = appearance.getString(attr);
                    }
                    attributes.mFontFamilyExplicit = true;
                    break;

然后看看哪里使用到mFontFamily。

//代码使用处  
 setTypefaceFromAttrs(attributes.mFontTypeface, attributes.mFontFamily,
                attributes.mTypefaceIndex, attributes.mStyleIndex, attributes.mFontWeight);
 
 
相关的方法
/**
     * Sets the Typeface taking into account the given attributes.
     *
     * @param typeface a typeface
     * @param familyName family name string, e.g. "serif"
     * @param typefaceIndex an index of the typeface enum, e.g. SANS, SERIF.
     * @param style a typeface style
     * @param weight a weight value for the Typeface or -1 if not specified.
     */
    private void setTypefaceFromAttrs(@Nullable Typeface typeface, @Nullable String familyName,
            @XMLTypefaceAttr int typefaceIndex, @Typeface.Style int style,
            @IntRange(from = -1, to = Typeface.MAX_WEIGHT) int weight) {
        if (typeface == null && familyName != null) {
            // Lookup normal Typeface from system font map.
            final Typeface normalTypeface = Typeface.create(familyName, Typeface.NORMAL);
            resolveStyleAndSetTypeface(normalTypeface, style, weight);
        } else if (typeface != null) {
            resolveStyleAndSetTypeface(typeface, style, weight);
        } else {  // both typeface and familyName is null.
            switch (typefaceIndex) {
                case SANS:
                    resolveStyleAndSetTypeface(Typeface.SANS_SERIF, style, weight);
                    break;
                case SERIF:
                    resolveStyleAndSetTypeface(Typeface.SERIF, style, weight);
                    break;
                case MONOSPACE:
                    resolveStyleAndSetTypeface(Typeface.MONOSPACE, style, weight);
                    break;
                case DEFAULT_TYPEFACE:
                default:
                    resolveStyleAndSetTypeface(null, style, weight);
                    break;
            }
        }
    }

所以参考源代码,我们就知道怎么使用了。

如果是TextView的话:

TextView textView=findViewById(R.id.text);
String familyName = "sans-serif-medium";
final Typeface normalTypeface = Typeface.create(familyName, Typeface.NORMAL);
textView.setTypeface(normalTypeface)

如果是TextPaint的话:

Paint paint = new Paint();
Typeface normalTypeface = Typeface.create("sans-serif-medium", Typeface.NORMAL);
paint.setTypeface(normalTypeface);

转自:https://blog.csdn.net/rzleilei/article/details/110636893

posted @ 2022-11-09 17:26 似水流云 阅读(795) 评论(0) 推荐(0) 编辑
摘要: 目前看到了两家打包实现: 美团 腾讯VasDolly 前言 其实本文大部分资料都来自github和google,如何有兴趣的读者,可以直接阅读官方文档~ 什么是Gradle Android 构建系统编译应用资源和源代码,然后将它们打包成可供您测试、部署、签署和分发的 APK。 Android Stu 阅读全文
posted @ 2022-10-25 16:54 似水流云 阅读(679) 评论(0) 推荐(0) 编辑
摘要: 近年来android权限审查越来越严格、各种理由被拒、其实开发者心里也苦、有些权限鬼知道在什么时候偷偷请求... 那么多sdk 一 一排查 岂不要了老命乎? 况且有些排查也是有难度的... 不是所有权限都有权限弹窗、如mac地址、设备号等... 推荐解决方案A(需要集成依赖,上线建议删除依赖):Gi 阅读全文
posted @ 2022-10-24 16:58 似水流云 阅读(651) 评论(0) 推荐(0) 编辑
摘要: 前天群里有人抛出app合规怎么测试,领导就抛出xx你去测试下app合规,然后这下群里就开始讨论,没有测试规范,没有测试标准怎么测试,有人讨论主动测试,寻找知识解决问题,走上加薪升职星光大道,有人说活多不加薪。讨论几百条信息,我是没仔细。但关注的是app合规要怎么测? 小组遇到一个app合规测试的需求 阅读全文
posted @ 2022-10-24 16:47 似水流云 阅读(224) 评论(0) 推荐(0) 编辑
摘要: 关键字 MaterialApp navigatorObservers Flutter的StatefulWidget StatelessWidget生命周期中没有组件出现或者消失的回调,主要是要靠路由的监听 创建一个路由监听 final RouteObserver<ModalRoute<void>> 阅读全文
posted @ 2022-10-20 14:37 似水流云 阅读(2163) 评论(0) 推荐(0) 编辑
摘要: 测试目的:避免受欢迎的app被工信部点名下架给公司造成影响 测试环境搭建: 手机先安装xposed,也就是虚拟系统,务必使用我提供的xpose的apk,不然你可能出现安装的xpose虚拟apk以后,在选择安装软件的时候,会出现不支持32位安装,这样就无法测试,这时你只能选择32位还是64位的Xpos 阅读全文
posted @ 2022-10-20 14:30 似水流云 阅读(1527) 评论(0) 推荐(0) 编辑
摘要: 一、认识++和-- ++。 当++在前面的时候,先自加1,后进行赋值操作;当++在后面的时候,先进行赋值操作,再自加1。 --。 当--在前面的时候,先自减1,后进行赋值操作;当--在后面的时候,先进行赋值操作,再自减1. /* ++:自加1 当++在前的时候,先自加1,再做赋值操作,当++在后的时 阅读全文
posted @ 2022-10-18 09:25 似水流云 阅读(600) 评论(0) 推荐(0) 编辑
摘要: 一、生命周期阶段 flutter生命周期大体上可以分为三个阶段:初始化、状态变化、销毁。 1、初始化阶段 对应执行构造方法和initState时候 2、状态变化阶段 开新的widget或者调用setState方法的时候 3、销毁阶段 deactivate 和 dispose 二、生命周期阶段执行的函 阅读全文
posted @ 2022-10-13 14:08 似水流云 阅读(254) 评论(0) 推荐(0) 编辑
摘要: 仔细一看不仅华为没有,其他机型也没有应用名称,如下图: 仔细一看确实没有名称,这时候查看代码发现:MaterialApp里面的title没有设置,这时候我们将其设置一个title就可以。 转自flutter 华为审核:你的应用存在隐藏最近任务列表中应用名称的问题,不符合华为应用市场审核标准 阅读全文
posted @ 2022-10-11 14:29 似水流云 阅读(1422) 评论(0) 推荐(0) 编辑
摘要: 1. 安装插件 配置flutter_swiper插件 # 配置轮播图插件 flutter_swiper: ^1.1.6 在pubspec.yaml中配置保存后,在VS Code环境中会自动下载依赖包。 如果无法正常下载,执行 flutter pub get 。 2. 引入依赖 在需要用到的该插件文件 阅读全文
posted @ 2022-09-28 13:47 似水流云 阅读(2076) 评论(0) 推荐(0) 编辑
点击右上角即可分享
微信分享提示