单击时,密码会在Leanback指导步骤操作中显示

时间:2018-11-29 13:49:33

标签: android leanback

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

当用户按下Enter键或转到下一个“引导式操作”时,如何防止“密码”的GuidedAction泄露键入的文本?

我面临的问题是用户键入时密码被隐藏,但是当用户转到下一个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,但是在用户转到下一个Action之后,仍然不能隐藏用户的密码。

@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);
}

1 个答案:

答案 0 :(得分:2)

以下代码有效

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()