tencent cloud

人脸核身

Android 自定义能力

下载
聚焦模式
字号
最后更新时间: 2026-10-29 11:05:36
本文档已由 AI 辅助审校
本文主要介绍海外版慧眼 SDK 当前所具备的自定义的能力

一、自定义 UI

自定义布局

慧眼 SDK 支持自定义 UI ,主要是通过 AuthUiConfig (可以参考 接口概述文档)配置参数实现,通过传入 Layout resId 的方式可自定义 UI 布局 。
使用方式大致如下:
AuthUiConfig authConfig = new AuthUiConfig();
authUiConfig.setAuthCircleCorrectColor(resources.getColor(R.color.demo_blue));
huiYanOsConfig.setAuthUiConfig(authConfig);
下图所示属于默认布局:



默认布局如上图所示,图中的所有控件的位置均可以通过修改布局 Layout.xml 进行修改。具体的可以参考 demo 中的 demo_huiyan_fragment_authing.xml 文件。
注意:
demo_huiyan_fragment_authing.xml 中的 View 类型以及对应的 android:id 由于参与界面事件绑定,请不要修改。
这里提供默认的布局如下:
<?xml version="1.0" encoding="utf-8"?>
<com.tencent.could.huiyansdk.view.HuiYanReflectLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/txy_auth_layout_bg"
android:layout_width="match_parent"
android:layout_height="match_parent">

<!-- 取消按钮 -->
<TextView
android:id="@+id/txy_cancel_txt_btn"
android:text="@string/txy_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:textColor="@color/txy_black"
android:textSize="@dimen/txy_tips_extra_text_size"
android:layout_marginTop="@dimen/txy_title_margin_top"
android:layout_marginStart="@dimen/txy_protocol_margin_size"
/>

<!-- 倒计时的显示控件 -->
<TextView
android:id="@+id/txy_count_down_txt_view"
android:text="@string/txy_count_down_txt"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:textSize="@dimen/txy_tips_extra_text_size"
android:textColor="@color/txy_black"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/txy_title_margin_top"
android:layout_marginRight="@dimen/txy_protocol_margin_size"
android:visibility="gone"
/>

<!-- 摄像头预览界面框 720P的话,代码中height会自定乘以1.3 -->
<com.tencent.could.huiyansdk.view.CameraDateGatherView
android:id="@+id/txy_camera_gather_view"
android:layout_width="@dimen/txy_auth_head_size"
android:layout_height="@dimen/txy_auth_head_default_height"
android:background="@android:color/transparent"
android:layout_marginBottom="@dimen/txy_auth_view_move"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<!-- 通用背景,待竖线的圆环 -->
<com.tencent.could.huiyansdk.view.CommonAuthBackView
android:id="@+id/txy_auth_common_background_views"
android:layout_width="@dimen/txy_auth_circle_size"
android:layout_height="@dimen/txy_auth_circle_size"
android:layout_marginBottom="@dimen/txy_auth_view_move"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>

<!-- 展示的头像图片 -->
<ImageView
android:id="@+id/txy_camera_prepare_img"
app:srcCompat="@drawable/txy_prepare_face_head_white"
android:layout_width="@dimen/txy_auth_head_size"
android:layout_height="@dimen/txy_auth_head_size"
android:layout_marginBottom="@dimen/txy_auth_view_move"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />

<!-- 前台的动画View -->
<com.tencent.could.huiyansdk.view.LoadingFrontAnimatorView
android:id="@+id/txy_auth_loading_front_animator_view"
android:visibility="gone"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginBottom="@dimen/txy_auth_view_move"
android:layout_width="@dimen/txy_auth_head_size"
android:layout_height="@dimen/txy_auth_head_size"
/>

<!-- 提示信息的展示界面 -->
<TextView
android:id="@+id/txy_auth_feed_back_txt"
app:layout_constraintTop_toBottomOf="@id/txy_auth_common_background_views"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:textColor="@color/txy_black"
android:layout_marginTop="@dimen/txy_protocol_line_space"
android:text="@string/txy_face_preparing3"
android:textSize="@dimen/txy_tips_text_size"
android:paddingHorizontal="@dimen/txy_title_margin_top"
android:gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>

<!-- 额外的警告信息的提示控件 -->
<TextView
android:id="@+id/txy_auth_feed_back_extra_tip_txt"
android:textSize="@dimen/txy_tips_extra_text_size"
android:textColor="@color/txy_black"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:paddingHorizontal="@dimen/txy_title_margin_top"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginTop="20dp"
app:layout_constraintTop_toBottomOf="@id/txy_auth_feed_back_txt"
/>

</com.tencent.could.huiyansdk.view.HuiYanReflectLayout>

自定义布局的事件绑定

上一节介绍了如何进行自定义 UI 布局,本节主要介绍如何对自定义 UI 布局里新增的控件进行事件绑定,以满足您在使用阶段的各项需求。
当核身界面被创建时,HuiYanAuthEventCallBack 的 onMainViewCreate ( View authView ) 被调用。当核身界面即将销毁的时候,会回调 onMainViewDestroy() 方法,您可以在对应的生命周期中自定义处理逻辑。
// 这里设置慧眼关键事件的回调监听
HuiYanOsApi.setAuthEventCallBack(new HuiYanAuthEventCallBack() {
@Override
public void onAuthTipsEvent(HuiYanAuthTipsEvent tipsEvent) {
Log.e(TAG, "current is : " + tipsEvent);
}

@Override
public void onMainViewCreate(View authView) {
if (authView == null) {
return;
}
// 获取自定义添加的控件,并且注册自定义的事件
Button findBtn = authView.findViewById(R.id.add_view_offer_button);
if (findBtn != null) {
findBtn.setOnClickListener(view -> {
Log.e(TAG, "click test button!");
});
}
}

@Override
public void onMainViewDestroy() {
Log.e(TAG, "onMainViewDestroy");
}
});
根据 onMainViewCreate 的回调与 onMainViewDestroy 的回调方式,您可以完成任意对应您新增 UI 控件的事件绑定,以实现对应效果。

二、自定义提示与增加语言

自定义提示

如果您需要修改提示语,或者新增其他的语言文件的话,可以按照下面的方式去实现。慧眼 SDK 会提供一个翻译文件 hy_customer_string.xml里面包括了所有慧眼 SDK 对外可以进行修改的配置文件
1. 在主 module(集成慧眼 SDK 的 module )工程。
2. 将hy_customer_string.xml 添加到对应的语言文件夹下。
3. 修改其中需要自定义的文字内容即可。
4. 打包以后,您修改的内容会自动覆盖原有的内容。




新增语言

新增语言的话,则需要执行以下两步就可以实现:
1. 在主 module(集成慧眼 SDK 的 module )工程里新增对应语言文件夹。
2. 将hy_customer_string.xml 拷贝到该语言文件夹下,并修改对应的 value 内容。



3. 在代码里指定对应的语言码即可(以泰文为例)。
huiYanOsConfig.setLanguageStyle(LanguageStyle.CUSTOMIZE_LANGUAGE);
huiYanOsConfig.setLanguageCode("th-TH");

三、常见接入集成问题

1. 集成 SDK 后出现 invoke-custom are only supported starting with Android O (--min-api 26)错误?
需要在 build.gradle 中添加如下配置:
// java版本支持1.8
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
2. 如果集成方使用了 AndResGuard 的混淆工具,可以添加混淆配置:
// for HuiYanSDK
"R.string.ocr_*",
"R.string.rst_*",
"R.string.net_*",
"R.string.msg_*",
"R.string.fl_*",
3. AndroidX 针对一些低版本的设备报错 android.content.res.Resources$NotFoundException:from xml type xml resource ID #0x7f0800c3 这一类的错误,可以考虑添加矢量图依赖:
// 低版本的矢量图
implementation 'androidx.vectordrawable:vectordrawable:1.1.0'
4. Android Support 如果在低版本设备上(6.0 及以下)出现如下报错:
android.content.res.Resources$NotFoundException: File res/drawable/$txy_face_id_logo__0.xml from color state list resource ID #0x7f070001
at android.content.res.Resources.loadColorStateListForCookie(Resources.java:2800)
at android.content.res.Resources.loadColorStateList(Resources.java:2749)
at android.content.res.TypedArray.getColor(TypedArray.java:441)
at android.content.res.XResources$XTypedArray.getColor(XResources.java:1286)
at android.support.v4.content.res.TypedArrayUtils.getNamedColor(TypedArrayUtils.java:124)
at android.support.graphics.drawable.VectorDrawableCompat$VFullPath.updateStateFromTypedArray(VectorDrawableCompat.java:1746)
at android.support.graphics.drawable.VectorDrawableCompat$VFullPath.inflate(VectorDrawableCompat.java:1712)
at android.support.graphics.drawable.VectorDrawableCompat.inflateInternal(VectorDrawableCompat.java:743)
at android.support.graphics.drawable.VectorDrawableCompat.inflate(VectorDrawableCompat.java:631)
at android.support.graphics.drawable.VectorDrawableCompat.createFromXmlInner(VectorDrawableCompat.java:590)
at android.support.v7.widget.AppCompatDrawableManager$VdcInflateDelegate.createFromXmlInner(AppCompatDrawableManager.java:775)
需要更新 support 依赖到最新版本 28.0.0 :
implementation 'com.android.support:appcompat-v7:28.0.0'
// 兼容低版本矢量图依赖的组件库
implementation 'com.android.support:support-vector-drawable:28.0.0'
implementation 'com.android.support:animated-vector-drawable:28.0.0'

附录 Android 语言码

这里提供一下 Android 的部分语言码,以供参考。
语言码
对应使用的国家或地区
af-ZA
公用荷兰语 - 南非
sq-AL
阿尔巴尼亚 -阿尔巴尼亚
ar-DZ
阿拉伯语 -阿尔及利亚
ar-BH
阿拉伯语 -巴林
ar-EG
阿拉伯语 -埃及
ar-IQ
阿拉伯语 -伊拉克
ar-JO
阿拉伯语 -约旦
ar-KW
阿拉伯语 -科威特
ar-LB
阿拉伯语 -黎巴嫩
ar-LY
阿拉伯语 -利比亚
ar-MA
阿拉伯语 -摩洛哥
ar-OM
阿拉伯语 -阿曼
ar-QA
阿拉伯语 -卡塔尔
eu-ES
巴斯克 -巴斯克
be-BY
Belarusian -白俄罗斯
bg-BG
保加利亚 -保加利亚
ca-ES
西班牙-加泰罗尼亚语
zh-HK
华语 - 中国香港
zh-MO
华语 - 中国澳门
zh-CN
华语 -中国
zh-SG
华语 -新加坡
zh-TW
华语 - 中国台湾
zh-CHS
华语 (简体)
zh-CHT
华语 (繁体)
hr-HR
克罗埃西亚 -克罗埃西亚
cs-CZ
捷克 - 捷克
da-DK
丹麦文 -丹麦
div-MV
Dhivehi -马尔代夫
nl-BE
荷兰 -比利时
nl-NL
荷兰 - 荷兰
en-AU
英语 -澳洲
en-CA
英语 -加拿大
en-ZA
英语 - 南非
en-PH
英语 -菲律宾共和国
en-NZ
英语 - 新西兰
en-GB
英语 - 英国
en-US
英语 - 美国
fa-IR
波斯语 -伊朗王国
fi-FI
芬兰语 -芬兰
fr-FR
法语 -法国
fr-BE
法语 -比利时
fr-MC
法语 -摩纳哥
fr-CH
法语 -瑞士
gl-ES
加利西亚 -加利西亚
ka-GE
格鲁吉亚 -格鲁吉亚语
de-DE
德语 -德国
de-LU
德语 -卢森堡
de-CH
德语 -瑞士
el-GR
希腊 -希腊
gu-IN
Gujarati -印度
he-IL
希伯来 -以色列
hi-IN
北印度语 -印度
hu-HU
匈牙利语 -匈牙利
is-IS
冰岛语 -冰岛
it-IT
意大利 -意大利
ja-JP
日本 -日本
kk-KZ
Kazakh -哈萨克
kn-IN
卡纳达语 -印度
ko-KR
韩国 -韩国
lv-LV
拉脱维亚语 -拉脱维亚
lt-LT
立陶宛 -立陶宛
ms-BN
马来语 -文莱
ms-MY
马来语 -马来西亚
mr-IN
马拉地语 -印度
mn-MN
蒙古 -蒙古
nn-NO
挪威 (Nynorsk) - 挪威
pl-PL
波兰 -波兰
pt-BR
葡萄牙语 -巴西
pt-PT
葡萄牙语 -葡萄牙
ro-RO
罗马尼亚语 -罗马尼亚
sa-IN
梵文 -印度
ru-RU
俄国 -俄国
sk-SK
斯洛伐克 -斯洛伐克
es-AR
西班牙语 -阿根廷
es-ES
西班牙语 -西班牙
sv-SE
瑞典 -瑞典
th-TH
泰国 -泰国
tr-TR
土耳其语 -土耳其
uk-UA
乌克兰 -乌克兰
ur-PK
Urdu -巴基斯坦
vi-VN
越南 -越南


帮助和支持

本页内容是否解决了您的问题?

填写满意度调查问卷,共创更好文档体验。

文档反馈