当前位置: 首页 > 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;首先…...

KubeSphere 容器平台高可用:环境搭建与可视化操作指南

Linux_k8s篇 欢迎来到Linux的世界&#xff0c;看笔记好好学多敲多打&#xff0c;每个人都是大神&#xff01; 题目&#xff1a;KubeSphere 容器平台高可用&#xff1a;环境搭建与可视化操作指南 版本号: 1.0,0 作者: 老王要学习 日期: 2025.06.05 适用环境: Ubuntu22 文档说…...

Spring Boot 实现流式响应(兼容 2.7.x)

在实际开发中&#xff0c;我们可能会遇到一些流式数据处理的场景&#xff0c;比如接收来自上游接口的 Server-Sent Events&#xff08;SSE&#xff09; 或 流式 JSON 内容&#xff0c;并将其原样中转给前端页面或客户端。这种情况下&#xff0c;传统的 RestTemplate 缓存机制会…...

shell脚本--常见案例

1、自动备份文件或目录 2、批量重命名文件 3、查找并删除指定名称的文件&#xff1a; 4、批量删除文件 5、查找并替换文件内容 6、批量创建文件 7、创建文件夹并移动文件 8、在文件夹中查找文件...

对WWDC 2025 Keynote 内容的预测

借助我们以往对苹果公司发展路径的深入研究经验&#xff0c;以及大语言模型的分析能力&#xff0c;我们系统梳理了多年来苹果 WWDC 主题演讲的规律。在 WWDC 2025 即将揭幕之际&#xff0c;我们让 ChatGPT 对今年的 Keynote 内容进行了一个初步预测&#xff0c;聊作存档。等到明…...

Ascend NPU上适配Step-Audio模型

1 概述 1.1 简述 Step-Audio 是业界首个集语音理解与生成控制一体化的产品级开源实时语音对话系统&#xff0c;支持多语言对话&#xff08;如 中文&#xff0c;英文&#xff0c;日语&#xff09;&#xff0c;语音情感&#xff08;如 开心&#xff0c;悲伤&#xff09;&#x…...

汇编常见指令

汇编常见指令 一、数据传送指令 指令功能示例说明MOV数据传送MOV EAX, 10将立即数 10 送入 EAXMOV [EBX], EAX将 EAX 值存入 EBX 指向的内存LEA加载有效地址LEA EAX, [EBX4]将 EBX4 的地址存入 EAX&#xff08;不访问内存&#xff09;XCHG交换数据XCHG EAX, EBX交换 EAX 和 EB…...

全面解析各类VPN技术:GRE、IPsec、L2TP、SSL与MPLS VPN对比

目录 引言 VPN技术概述 GRE VPN 3.1 GRE封装结构 3.2 GRE的应用场景 GRE over IPsec 4.1 GRE over IPsec封装结构 4.2 为什么使用GRE over IPsec&#xff1f; IPsec VPN 5.1 IPsec传输模式&#xff08;Transport Mode&#xff09; 5.2 IPsec隧道模式&#xff08;Tunne…...

python报错No module named ‘tensorflow.keras‘

是由于不同版本的tensorflow下的keras所在的路径不同&#xff0c;结合所安装的tensorflow的目录结构修改from语句即可。 原语句&#xff1a; from tensorflow.keras.layers import Conv1D, MaxPooling1D, LSTM, Dense 修改后&#xff1a; from tensorflow.python.keras.lay…...

在Ubuntu24上采用Wine打开SourceInsight

1. 安装wine sudo apt install wine 2. 安装32位库支持,SourceInsight是32位程序 sudo dpkg --add-architecture i386 sudo apt update sudo apt install wine32:i386 3. 验证安装 wine --version 4. 安装必要的字体和库(解决显示问题) sudo apt install fonts-wqy…...

排序算法总结(C++)

目录 一、稳定性二、排序算法选择、冒泡、插入排序归并排序随机快速排序堆排序基数排序计数排序 三、总结 一、稳定性 排序算法的稳定性是指&#xff1a;同样大小的样本 **&#xff08;同样大小的数据&#xff09;**在排序之后不会改变原始的相对次序。 稳定性对基础类型对象…...