单击时会在 Leanback Guided Step Action 上显示密码

Password is revealed on Leanback Guided Step Action when clicked

我的 Leanback 应用程序中有一个 GuidedStepFragment 作为身份验证类型片段。

如何防止 "password" GuidedAction 在用户按下回车键或转到下一个 Guided Action 时显示键入的文本?

我面临的问题是密码在用户键入时隐藏,但在用户转到下一个 GuidedAction 时显示

@Override
public void onCreateActions(@NonNull List<GuidedAction> actions, Bundle savedInstanceState) {
    GuidedAction action;
    if (getArguments() != null) {
        type = getArguments().getInt(ARG_TYPE);
    }
    if (type == TYPE_EMAIL) {
        action = new GuidedAction.Builder(getActivity())
                .id(ActionConstants.ACTION_INPUT_EMAIL)
                .editable(true)
                .description(getString(R.string.email_address_hint))
                .editInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS)
                .build();
    } else {
        action = new GuidedAction.Builder(getActivity())
                .id(ActionConstants.ACTION_INPUT_PASS)
                .editable(true)
                .description(getString(R.string.password))
                .editInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD)
                .build();
    }
    actions.add(action);
    action = new GuidedAction.Builder(getActivity())
            .id(ActionConstants.ACTION_CONTINUE)
            .title(R.string.next)
            .hasNext(true) // Shows the small arrow indicating there's something next...
            .build();
    actions.add(action);
}

我已尝试重写 setupImeOptions 以在 EditText 上显式设置 TransformationMethod,但在用户转到下一个操作后仍然无法隐藏用户密码。

@Override
protected void setupImeOptions(ViewHolder vh, GuidedAction action) {
    switch ((int) action.getId()) {
        case ActionConstants.ACTION_INPUT_PASS :
            vh.getEditableDescriptionView().setTransformationMethod(new PasswordTransformationMethod());
            vh.getEditableTitleView().setTransformationMethod(new PasswordTransformationMethod());
            break;
    }
    super.setupImeOptions(vh, action);
}

以下代码有效

GuidedAction.Builder(activity)
            .id(PASSWORD.toLong())
            .title("Password")
            .descriptionEditable(true)
            .descriptionInputType(InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_PASSWORD)
            .descriptionEditInputType(InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_PASSWORD)
            .build()