当前位置: 首页 > news >正文

android 12添加系统字体并且设置为默认字体

需求:在11.0 12.0系统定制化开发中,在产品定制中,有产品需求对于系统字体风格不太满意,所以想要更换系统的默认字体,对于系统字体的修改也是常有的功能,而系统默认也支持增加字体,所以就来添加楷体字体为系统字体,并替换为系统默认字体。

  1. 添加系统字体并且设置为默认字体的核心类

frameworks/base/data/fonts/
frameworks/base/data/fonts/fonts.mk
frameworks/base/data/fonts/Android.mk
frameworks/base/data/fonts/fonts.xml 
  1. 添加系统字体并且设置为默认字体核心功能实现和分析

对于系统添加新字体功能,是默认支持的但是有些字体会导致系统的支持性不是太好,所以要选择好系统字体也是比较关键的

具体步骤如下:

2.1fonts下增加新字体

在目录frameworks/base/data/fonts/ 添加 KTFont.ttf

2.2 在frameworks/base/data/fonts/fonts.mk中添加新的字体

具体先看fonts.mk文件

# Copyright (C) 2008 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software# distributed under the License is distributed on an "AS IS" BASIS,# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# See the License for the specific language governing permissions and# limitations under the License.# Warning: this is actually a product definition, to be inherited fromPRODUCT_PACKAGES := \DroidSansMono.ttf \AndroidClock.ttf \fonts.xml

增加新字体如下:

PRODUCT_PACKAGES := \DroidSansMono.ttf \AndroidClock.ttf \
+    KTFont.ttf \fonts.xml

2.3 在frameworks/base/data/fonts/Android.mk中添加新的字体

在font_src_files 添加新增的字体格式,如下

 ################################# Build the rest of font files as prebuilt.# $(1): The source file name in LOCAL_PATH.#       It also serves as the module name and the dest file name.define build-one-font-module$(eval include $(CLEAR_VARS))\$(eval LOCAL_MODULE := $(1))\$(eval LOCAL_SRC_FILES := $(1))\$(eval LOCAL_MODULE_CLASS := ETC)\$(eval LOCAL_MODULE_TAGS := optional)\$(eval LOCAL_MODULE_PATH := $(TARGET_OUT)/fonts)\$(eval include $(BUILD_PREBUILT))endef
font_src_files := \AndroidClock.ttf \KTFont.ttf

2.4fonts.xml配置默认字体作为默认系统字体

frameworks/base/data/fonts/fonts.xml 中替换默认字体

先来看下 fonts.xml

<?xml version="1.0" encoding="utf-8"?>
<!--WARNING: Parsing of this file by third-party apps is not supported. Thefile, and the font files it refers to, will be renamed and/or moved outfrom their respective location in the next Android release, and/or theformat or syntax of the file may change significantly. If you parse thisfile for information about system fonts, do it at your own risk. Yourapplication will almost certainly break with the next major Androidrelease.In this file, all fonts without names are added to the default list.Fonts are chosen based on a match: full BCP-47 language tag includingscript, then just language, and finally order (the first font containingthe glyph).Order of appearance is also the tiebreaker for weight matching. This isthe reason why the 900 weights of Roboto precede the 700 weights - weprefer the former when an 800 weight is requested. Since bold spanseffectively add 300 to the weight, this ensures that 900 is the boldpaired with the 500 weight, ensuring adequate contrast.
-->
<familyset version="23"><!-- first font is default --><family name="sans-serif"><font weight="100" style="normal">Roboto-Thin.ttf</font><font weight="100" style="italic">Roboto-ThinItalic.ttf</font><font weight="300" style="normal">Roboto-Light.ttf</font><font weight="300" style="italic">Roboto-LightItalic.ttf</font><font weight="400" style="normal">Roboto-Regular.ttf</font><font weight="400" style="italic">Roboto-Italic.ttf</font><font weight="500" style="normal">Roboto-Medium.ttf</font><font weight="500" style="italic">Roboto-MediumItalic.ttf</font><font weight="900" style="normal">Roboto-Black.ttf</font><font weight="900" style="italic">Roboto-BlackItalic.ttf</font><font weight="700" style="normal">Roboto-Bold.ttf</font><font weight="700" style="italic">Roboto-BoldItalic.ttf</font></family><!-- Note that aliases must come after the fonts they reference. --><alias name="sans-serif-thin" to="sans-serif" weight="100" /><alias name="sans-serif-light" to="sans-serif" weight="300" /><alias name="sans-serif-medium" to="sans-serif" weight="500" /><alias name="sans-serif-black" to="sans-serif" weight="900" /><alias name="arial" to="sans-serif" /><alias name="helvetica" to="sans-serif" /><alias name="tahoma" to="sans-serif" /><alias name="verdana" to="sans-serif" /><family name="sans-serif-condensed"><font weight="300" style="normal">RobotoCondensed-Light.ttf</font><font weight="300" style="italic">RobotoCondensed-LightItalic.ttf</font><font weight="400" style="normal">RobotoCondensed-Regular.ttf</font><font weight="400" style="italic">RobotoCondensed-Italic.ttf</font><font weight="500" style="normal">RobotoCondensed-Medium.ttf</font><font weight="500" style="italic">RobotoCondensed-MediumItalic.ttf</font><font weight="700" style="normal">RobotoCondensed-Bold.ttf</font><font weight="700" style="italic">RobotoCondensed-BoldItalic.ttf</font></family>。。。。。

通过阅读代码发现第一个family 就是默认的字体KTFont.ttf 所以要把添加在一条就行了

所以修改如下:

 <familyset version="23"><!-- first font is default --><family name="sans-serif">
+           <font weight="400" style="normal">KTFont.ttf</font><font weight="100" style="normal">Roboto-Thin.ttf</font><font weight="100" style="italic">Roboto-ThinItalic.ttf</font><font weight="300" style="normal">Roboto-Light.ttf</font><font weight="300" style="italic">Roboto-LightItalic.ttf</font>
-        <font weight="400" style="normal">Roboto-Regular.ttf</font>
+        <!--font weight="400" style="normal">Roboto-Regular.ttf</font--><font weight="400" style="italic">Roboto-Italic.ttf</font><font weight="500" style="normal">Roboto-Medium.ttf</font><font weight="500" style="italic">Roboto-MediumItalic.ttf</font>
@@ -545,10 +546,7 @@<family>

同时注意要注释掉相同属性的 Roboto-Regular.ttf的字体 不然系统会抛异常开不了机

在加载系统默认字体的时候 weight 400的字体已经存在了 所以要注释掉一个即可

相关文章:

android 12添加系统字体并且设置为默认字体

需求&#xff1a;在11.0 12.0系统定制化开发中&#xff0c;在产品定制中&#xff0c;有产品需求对于系统字体风格不太满意&#xff0c;所以想要更换系统的默认字体&#xff0c;对于系统字体的修改也是常有的功能&#xff0c;而系统默认也支持增加字体&#xff0c;所以就来添加楷…...

LeetCode刷题系列 -- 1094. 拼车

车上最初有 capacity 个空座位。车 只能 向一个方向行驶&#xff08;也就是说&#xff0c;不允许掉头或改变方向&#xff09;给定整数 capacity 和一个数组 trips , trip[i] [numPassengersi, fromi, toi] 表示第 i 次旅行有 numPassengersi 乘客&#xff0c;接他们和放他们的…...

二叉查找树的应用 —— K模型和KV模型

文章目录前言1. K模型2. KV模型&#x1f351; 构建KV模型的树&#x1f351; 英汉词典&#x1f351; 统计水果出现的次数3. 总结前言 在上一篇文章中&#xff0c;我们进行了二叉查找树的实现&#xff08;文章链接&#xff09;&#xff0c;那么今天主要探讨一下二叉查找树的应用…...

深度学习实战(11):使用多层感知器分类器对手写数字进行分类

使用多层感知器分类器对手写数字进行分类 1.简介 1.1 什么是多层感知器&#xff08;MLP&#xff09;&#xff1f; MLP 是一种监督机器学习 (ML) 算法&#xff0c;属于前馈人工神经网络 [1] 类。该算法本质上是在数据上进行训练以学习函数。给定一组特征和一个目标变量&#x…...

ThingsBoard-警报

1、使用 IoT 设备警报 ThingsBoard 提供了创建和管理与您的实体相关的警报的能力:设备、资产、客户等。例如,您可以将 ThingsBoard 配置为在温度传感器读数高于某个阈值时自动创建警报。当然,这是一个非常简化的案例,实际场景可能要复杂得多。 2、主要概念 下面让我们回…...

如何去阅读源码,我总结了18条心法

在聊如何去阅读源码之前&#xff0c;先来简单说一下为什么要去阅读源码&#xff0c;大致可分为以下几点原因&#xff1a;最直接的原因&#xff0c;就是面试需要&#xff0c;面试喜欢问源码&#xff0c;读完源码才可以跟面试官battle提升自己的编程水平&#xff0c;学习编程思想…...

排序:归并排序

一、归并 li[2,4,5,7,//1,3,6,8]#归并的前提是必须两部分排好序 def merge(li,low,mid,high):ilowjmid1ltmp[]while i<mid and j<high: #只要左右两边都有数if li[i]<li[j]:ltmp.append(li[i])i1else:ltmp.append(li[j])j1#while执行完&#xff0c;肯定有一部分没数…...

Allegro172版本线到铜皮不按照设定值避让的原因和解决办法

Allegro172版本线到铜皮不按照设定值避让的原因和解决办法 用Allegro做PCB设计的时候,有时会单独给某块铜皮附上线到铜皮额外再增加一个数值,如下图 在规则的基础上,额外再避让10mil 规则避让line到铜皮10.02mil 额外设置多避让10mil,避让的结果却是30.02mil,正确的是20.…...

小白该从哪方面入手学习大数据

大数据本质上是海量数据。 以往的数据开发&#xff0c;需要一定的Java基础和工作经验&#xff0c;门槛高&#xff0c;入门难。 如果零基础入门数据开发行业的小伙伴&#xff0c;可以从Python语言入手。 Python语言简单易懂&#xff0c;适合零基础入门&#xff0c;在编程语言…...

尚医通(十)数据字典加Redis缓存 | MongoDB

目录一、Redis介绍二、数据字典模块添加Redis缓存1、service_cmn模块&#xff0c;添加redis依赖2、service_cmn模块&#xff0c;添加Redis配置类3、在service_cmn模块&#xff0c;配置文件添加redis配置4、通过注解添加redis缓存5、查询数据字典列表添加Redis缓存6、bug&#x…...

为什么我们不再发明编程语言了?

上个世纪&#xff0c;数百种编程语言被发明出来&#xff0c;但是进入21世纪&#xff0c;当我们都进入互联网时代时&#xff0c;只剩那么寥寥几个了。 如果你翻一下TIOBE得编程语言排行榜&#xff0c;就会发现20年来&#xff0c;上蹿下跳的就是那几张老面孔&#xff1a;C , Java…...

预处理指令详解

预处理指令详解**1.预定义符号****2.#define****2.1 #define 定义标识符****2.2 #define 定义宏****2.3 #define 替换规则****2.4 #和##****#的作用****##的作用****2.5 带副作用的宏参数****2.6 宏和函数的对比****宏和函数对比图****2.7 命名约定****3.#undef**4.条件编译4.1…...

Redis

一.认识NoSQL 1.SQL 关系型数据库 结构化: 定义主键&#xff0c;无符号型数据等关联的&#xff1a;结构化表和表之间的关系通过外键进行关联&#xff0c;节省存储空间SQL查询&#xff1a;语法固定 SELECT id,name,age FROM tb_user WHERE id1 ACID 2.NoSQL 非关系型数据库 Re…...

Elasticsearch5.5.1 自定义评分插件开发

文本相似度插件开发&#xff0c;本文基于Elasticsearch5.5.1&#xff0c;Kibana5.5.1 下载地址为&#xff1a; Past Releases of Elastic Stack Software | Elastic 本地启动两个服务后&#xff0c;localhost:5601打开Kibana界面&#xff0c;点击devTools&#xff0c;效果图…...

4.4 序列化与反序列化

文章目录1.概述2.特点/应用场景3.涉及到的流对象4.代码实现序列化与反序列化4.1 步骤1&#xff1a;创建学生类Student24.2 步骤2&#xff1a;创建序列化测试类5.测试案例中常见的几种编译错误类型6.为什么反序列化版本号需要与序列化版本号一致&#xff1f;7.自动提示 生成UID …...

647. 回文子串 516. 最长回文子序列

647. 回文子串 方法一&#xff1a;动态规划 dp[i][j]:[i,j]范围的下标字符串s是否为回文子串 遍历字符串&#xff0c;每次判断s[i]与s[j]是否相等 ①若相等&#xff0c;j-i0 即单个字符串s[i]&#xff0c;那么一定为回文子串&#xff0c;赋值为1 ②若相等&#xff0c;j-i1…...

实用小妙招

记录一些实用小妙招&#xff0c;都是收藏夹里收藏的各种文章&#xff0c;总结在一起&#xff0c;持续更新 实用小妙招LinuxUbuntu修改终端语言安装 Node.js (nvm)git 记住账号密码WSL迁移默认用户修改Linux Ubuntu 修改终端语言 apt update apt install -y language-pack-zh…...

别让猴子跳回背上

1.管理者的贡献来自于他们的判断力与影响力&#xff0c;而非他们所投入的个人时间与埋头苦干 2.管理者的绩效表现则是许多人群策群力的结果 3.管理者的时间管理: 老板占用的时间;组织占用的时间;自己占用的时间;外界占用的时间; 4.管理者的策略在于增加自己的时间&#xff0c…...

数据结构 | 线性表

&#x1f525;Go for it!&#x1f525; &#x1f4dd;个人主页&#xff1a;按键难防 &#x1f4eb; 如果文章知识点有错误的地方&#xff0c;请指正&#xff01;和大家一起学习&#xff0c;一起进步&#x1f440; &#x1f4d6;系列专栏&#xff1a;数据结构与算法 &#x1f52…...

Deepwalk深度游走算法

主要思想 Deepwalk是一种将随机游走和word2vec两种算法相结合的图结构数据的挖掘算法。该算法可以学习网络的隐藏信息&#xff0c;能够将图中的节点表示为一个包含潜在信息的向量&#xff0c; Deepwalk算法 该算法主要分为随机游走和生成表示向量两个部分&#xff0c;首先…...

观成科技:隐蔽隧道工具Ligolo-ng加密流量分析

1.工具介绍 Ligolo-ng是一款由go编写的高效隧道工具&#xff0c;该工具基于TUN接口实现其功能&#xff0c;利用反向TCP/TLS连接建立一条隐蔽的通信信道&#xff0c;支持使用Let’s Encrypt自动生成证书。Ligolo-ng的通信隐蔽性体现在其支持多种连接方式&#xff0c;适应复杂网…...

基于大模型的 UI 自动化系统

基于大模型的 UI 自动化系统 下面是一个完整的 Python 系统,利用大模型实现智能 UI 自动化,结合计算机视觉和自然语言处理技术,实现"看屏操作"的能力。 系统架构设计 #mermaid-svg-2gn2GRvh5WCP2ktF {font-family:"trebuchet ms",verdana,arial,sans-…...

简易版抽奖活动的设计技术方案

1.前言 本技术方案旨在设计一套完整且可靠的抽奖活动逻辑,确保抽奖活动能够公平、公正、公开地进行,同时满足高并发访问、数据安全存储与高效处理等需求,为用户提供流畅的抽奖体验,助力业务顺利开展。本方案将涵盖抽奖活动的整体架构设计、核心流程逻辑、关键功能实现以及…...

【android bluetooth 框架分析 04】【bt-framework 层详解 1】【BluetoothProperties介绍】

1. BluetoothProperties介绍 libsysprop/srcs/android/sysprop/BluetoothProperties.sysprop BluetoothProperties.sysprop 是 Android AOSP 中的一种 系统属性定义文件&#xff08;System Property Definition File&#xff09;&#xff0c;用于声明和管理 Bluetooth 模块相…...

C++ 求圆面积的程序(Program to find area of a circle)

给定半径r&#xff0c;求圆的面积。圆的面积应精确到小数点后5位。 例子&#xff1a; 输入&#xff1a;r 5 输出&#xff1a;78.53982 解释&#xff1a;由于面积 PI * r * r 3.14159265358979323846 * 5 * 5 78.53982&#xff0c;因为我们只保留小数点后 5 位数字。 输…...

Spring AI与Spring Modulith核心技术解析

Spring AI核心架构解析 Spring AI&#xff08;https://spring.io/projects/spring-ai&#xff09;作为Spring生态中的AI集成框架&#xff0c;其核心设计理念是通过模块化架构降低AI应用的开发复杂度。与Python生态中的LangChain/LlamaIndex等工具类似&#xff0c;但特别为多语…...

重启Eureka集群中的节点,对已经注册的服务有什么影响

先看答案&#xff0c;如果正确地操作&#xff0c;重启Eureka集群中的节点&#xff0c;对已经注册的服务影响非常小&#xff0c;甚至可以做到无感知。 但如果操作不当&#xff0c;可能会引发短暂的服务发现问题。 下面我们从Eureka的核心工作原理来详细分析这个问题。 Eureka的…...

MySQL 8.0 事务全面讲解

以下是一个结合两次回答的 MySQL 8.0 事务全面讲解&#xff0c;涵盖了事务的核心概念、操作示例、失败回滚、隔离级别、事务性 DDL 和 XA 事务等内容&#xff0c;并修正了查看隔离级别的命令。 MySQL 8.0 事务全面讲解 一、事务的核心概念&#xff08;ACID&#xff09; 事务是…...

mac:大模型系列测试

0 MAC 前几天经过学生优惠以及国补17K入手了mac studio,然后这两天亲自测试其模型行运用能力如何&#xff0c;是否支持微调、推理速度等能力。下面进入正文。 1 mac 与 unsloth 按照下面的进行安装以及测试&#xff0c;是可以跑通文章里面的代码。训练速度也是很快的。 注意…...

图解JavaScript原型:原型链及其分析 | JavaScript图解

​​ 忽略该图的细节&#xff08;如内存地址值没有用二进制&#xff09; 以下是对该图进一步的理解和总结 1. JS 对象概念的辨析 对象是什么&#xff1a;保存在堆中一块区域&#xff0c;同时在栈中有一块区域保存其在堆中的地址&#xff08;也就是我们通常说的该变量指向谁&…...