DPI
DPI,全称Dots Per Inch,是一个衡量屏幕密度的关键指标。其中,Inch(英寸)作为物理单位,在任何设备上的大小都是恒定不变的。因此,DPI具体指的是在一英寸的物理长度内所能容纳的像素点(Dot)数量。例如,160DPI的屏幕意味着在一英寸的长度内包含160个像素点,而320DPI的屏幕则表明一英寸内含有320个像素点。由此可见,像素点的大小并不是固定的,而是随着DPI值的增加而减小。
在Android设备中,DPI被用来表示屏幕的密度(Density)。屏幕密度越大,意味着在一英寸的长度内所能显示的像素点数量越多,从而呈现出更加细腻、清晰的图像效果
adb命令修改Android设备的density
1. 用电脑连接上android设备 可以通过两种方式:
- **无线连接:**打开cmd.exe
输入 adb connect 移动设备的ip地址 (一定要确保电脑的网络和移动设备的网络在同一个局域网下面) - **有线连接:**usb数据线连接电脑和移动设备
2. 在cmd界面输入 adb shell wm density 想要修改的dpi值(160)
PS C:\Users\longzhiye> adb shell wm density
Physical density: 420
查看当前设备的dpi值为420
S C:\Users\longzhiye> adb shell wm density 300
修改前的效果
修改后的效果
通过观察可以发现,图标和字体明显变小
调整到合适的DPI以后,我们需要在源码中修改
frameworks/base/packages/SettingsProvider/res/values/defaults.xml
diff --git a/frameworks/base/packages/SettingsProvider/res/values/defaults.xml b/frameworks/base/packages/SettingsProvider/res/values/defaults.xml
index 5cb4c404e09..c1e220b614a 100755
--- a/frameworks/base/packages/SettingsProvider/res/values/defaults.xml
+++ b/frameworks/base/packages/SettingsProvider/res/values/defaults.xml
@@ -339,9 +341,19 @@
<bool name="def_status_bar_show_vibrate_icon">true</bool>
+ <!--Create by yeruilai 2022-12-7 10:09:39 -->
- <string name="def_display_density_forced" translatable="false">420</string>
+ <string name="def_display_density_forced" translatable="false">300</string>
+
</resources>
frameworks/base/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java
diff --git a/frameworks/base/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java b/frameworks/base/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java
index 53eef230cac..a3c96455cfa 100755
--- a/frameworks/base/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java
+++ b/frameworks/base/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java
@@ -2448,8 +2448,13 @@ class DatabaseHelper extends SQLiteOpenHelper {
loadIntegerSetting(stmt, UnisocSettings.Secure.FACE_UNLOCK_REQUIRE_LIVENESSMODE,
R.integer.def_facelock_liveness);
/*@}*/
- //loadStringSetting(stmt, Settings.Secure.DISPLAY_DENSITY_FORCED,
- //R.string.def_display_density_forced);
+ loadStringSetting(stmt, Settings.Secure.DISPLAY_DENSITY_FORCED,
+ R.string.def_display_density_forced);
/*
* IMPORTANT: Do not add any more upgrade steps here as the global,
* secure, and system settings are no longer stored in a database
标签:density,Android13,settings,frameworks,base,packages,SettingsProvider,dpi
From: https://blog.csdn.net/u010345983/article/details/143118307