Delphi Android手机 字体列表
时间: 2024-01-10 09:20:54 浏览: 29
在 Delphi 中获取 Android 手机的字体列表可以使用以下代码:
```delphi
uses
Androidapi.JNI.GraphicsContentViewText,
Androidapi.JNI.JavaTypes;
function GetInstalledFonts: TArray<string>;
var
TypefaceCls: JNIClass;
FontManagerObj: JObject;
GetFamiliesMethod: JNIMethod;
TypefaceArray: TJavaObjectArray<JObject>;
TypefaceObj: JObject;
TypefacesArray: TJavaObjectArray<JObject>;
i, j: Integer;
NameStr: JString;
begin
TypefaceCls := TJTypeface.JavaClass;
FontManagerObj := SharedActivityContext.getSystemService(TJContext.JavaClass.FONT_SERVICE);
GetFamiliesMethod := TypefaceCls.getMethod('getFamilies', [JInteger.JavaClass]);
TypefaceArray := TJTypeface.JavaClass.getFontFamilyFiles;
TypefacesArray := TJTypeface.JavaClass.getAvailableFontFamilyNames(SharedActivityContext);
SetLength(Result, TypefacesArray.Length);
for i := 0 to TypefacesArray.Length - 1 do
begin
TypefaceObj := TypefacesArray.GetRawItem(i);
GetFamiliesMethod.invoke(TypefaceCls, FontManagerObj, TypefaceObj);
for j := 0 to TypefaceArray.Length - 1 do
begin
NameStr := TJString.JavaClass.init(TJString.Wrap(TypefaceArray.GetRawItem(j)));
if NameStr.compareTo(TypefaceObj.toString) = 0 then
begin
Result[i] := JStringToString(NameStr);
Break;
end;
end;
end;
end;
```
这个函数会返回一个字符串数组,其中包含了 Android 手机上安装的所有字体的名称。你可以在你的应用程序中调用这个函数来获取字体列表。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)