Android TvSettings Bug: 密码框无法点击唤起输入法

这篇具有很好参考价值的文章主要介绍了Android TvSettings Bug: 密码框无法点击唤起输入法。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

概述

       Android 10 的Box方案, 默认使用的是TvSettings作为系统设置,输入操作的习惯上是使用鼠标,键盘,遥控,日常的场景是没有问题,也不会出现本文中提及的问题。当外接的USB触摸屏后,出现无法点击WIFI密码框换出输入法进行输入密码操作。

问题:
Android TvSettings Bug: 密码框无法点击唤起输入法,android-framework,android,android,bug,TvSettings,输入法,点击
Android TvSettings Bug: 密码框无法点击唤起输入法,android-framework,android,android,bug,TvSettings,输入法,点击
从图1开始添加WIFI,并准备输入密码时,外接的USB触摸屏没有办法点击唤起输入法。

正常的情况应该如下图所示:
Android TvSettings Bug: 密码框无法点击唤起输入法,android-framework,android,android,bug,TvSettings,输入法,点击

过程

     在前面的一些文章中,对于无法点击或响应按键操作的问题,一般可以先查查焦点的问题:

View Hierarchy:
      DecorView@661bdd7[WifiConnectionActivity]
        android.widget.LinearLayout{abf86c4 V.E...... ........ 0,0-1920,1080}
          android.view.ViewStub{e3449ad G.E...... ......I. 0,0-0,0 #10201a2 android:id/action_mode_bar_stub}
          android.widget.FrameLayout{38444e2 V.E...... ........ 0,0-1920,1080 #1020002 android:id/content}
            android.widget.FrameLayout{51a6073 V.E...... ........ 0,0-1920,1080 #7f0a0229 app:id/wifi_container}
              androidx.leanback.app.GuidedStepRootLayout{1904b30 V.E...... ........ 0,0-1920,1080 #7f0a0105 app:id/guidedstep_root}
                android.widget.FrameLayout{878d3a9 V.E...... ........ 0,0-1920,1080 #7f0a0104 app:id/guidedstep_background_view_root}
                  androidx.leanback.widget.NonOverlappingView{9a5cd2e V.ED..... ........ 0,0-1920,1080 #7f0a0103 app:id/guidedstep_background}
                  android.widget.LinearLayout{fb090cf V.E...... ........ 0,0-1920,1080 #7f0a00a0 app:id/content_frame}
                    androidx.leanback.widget.NonOverlappingFrameLayout{966ea5c V.E...... ........ 0,0-1231,1080 #7f0a009f app:id/content_fragment}
                      com.android.tv.settings.connectivity.setup.GuidanceRelativeLayout{b620165 V.E...... ........ 0,0-1231,1080}
                        android.widget.TextView{e458e3a V.ED..... ........ 168,374-1147,447 #7f0a00f1 app:id/guidance_title}
                        android.widget.TextView{fcf6aeb V.ED..... ........ 168,474-1147,503 #7f0a00ef app:id/guidance_description}
                    androidx.leanback.widget.NonOverlappingFrameLayout{aa65048 V.E...... ........ 1231,0-1919,1080 #7f0a0044 app:id/action_fragment_root}
                      androidx.leanback.widget.NonOverlappingView{4f64ee1 V.ED..... ........ 0,0-688,1080 #7f0a0043 app:id/action_fragment_background}
                      androidx.leanback.widget.NonOverlappingLinearLayout{bee5406 VFE...... ........ 0,0-688,1080 #7f0a0042 app:id/action_fragment}
                        android.widget.RelativeLayout{4b7cac7 V.E...... ........ 0,0-688,1080 #7f0a00ff app:id/guidedactions_root}
                          androidx.leanback.widget.NonOverlappingView{ef428f4 G.ED..... ......ID 0,0-0,0 #7f0a00fd app:id/guidedactions_list_background}
                          androidx.leanback.widget.GuidedActionsRelativeLayout{327f81d V.E...... ........ 0,0-688,1080 #7f0a00f3 app:id/guidedactions_content}
                            androidx.leanback.widget.VerticalGridView{90baa92 V.E...... ........ 0,0-348,1080 #7f0a00fb app:id/guidedactions_list}
                              android.widget.LinearLayout{6dc4c63 VFE...C.. ........ 0,103-348,528}
                                android.widget.FrameLayout{2a4e060 V.E...... ........ 0,293-348,365 #7f0a020f app:id/text_input_wrapper}
                                  android.widget.EditText{6d0f919 VFED..... ........ 24,0-324,72 #7f0a00fa app:id/guidedactions_item_title}
                                android.widget.CheckBox{535ddde VFED..C.. ........ 14,377-146,425 #7f0a01ac app:id/password_checkbox}
                            androidx.leanback.widget.NonOverlappingView{93d4bbf G.ED..... ......ID 0,0-0,0 #7f0a0102 app:id/guidedactions_sub_list_background}
                            androidx.leanback.widget.VerticalGridView{e7a28c IFE...... ......I. 0,432-688,432 #7f0a0101 app:id/guidedactions_sub_list}
                        android.widget.RelativeLayout{a6f0dd5 V.E...... ........ 688,0-688,1080 #7f0a0100 app:id/guidedactions_root2}
                          androidx.leanback.widget.NonOverlappingView{f3df9ea V.ED..... ......ID 0,0-0,1080 #7f0a00fe app:id/guidedactions_list_background2}
                          androidx.leanback.widget.NonOverlappingFrameLayout{484e4db V.E...... ......ID 0,0-0,1080 #7f0a00f4 app:id/guidedactions_content2}
                            androidx.leanback.widget.VerticalGridView{6b25b78 V.E...... ......ID 0,0-0,1080 #7f0a00fc app:id/guidedactions_list2}

很明显android.widget.EditText{6d0f919 VFED… … 24,0-324,72 #7f0a00fa app:id/guidedactions_item_title} 不可点击.

通过ID找到相关的代码:

$ grep -r "guidedactions_item_title" packages/apps/TvSettings/Settings
packages/apps/TvSettings/Settings/res/layout/setup_text_input_item.xml:            android:id="@+id/guidedactions_item_title"
packages/apps/TvSettings/Settings/res/layout/setup_password_item.xml:            android:id="@+id/guidedactions_item_title"
packages/apps/TvSettings/Settings/src/com/android/tv/settings/connectivity/util/GuidedActionsAlignUtil.java:                        androidx.leanback.R.id.guidedactions_item_title);
packages/apps/TvSettings/Settings/src/com/android/tv/settings/util/GuidedActionsAlignUtil.java:                        androidx.leanback.R.id.guidedactions_item_title);

packages/apps/TvSettings/Settings/res/layout/setup_password_item.xml

<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2017 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clipChildren="false"
    android:clipToPadding="false"
    android:orientation="vertical">

    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/text_input_wrapper"
        android:layout_width="match_parent"
        android:layout_height="@dimen/setup_list_item_height"
        android:layout_alignParentStart="true"
        android:layout_marginTop="@dimen/setup_action_vertical_offset"
        android:background="@drawable/setup_text_input_background"
        android:elevation="@dimen/setup_elevation"
        android:gravity="start|center_vertical"
        android:paddingEnd="@dimen/setup_list_item_padding"
        android:paddingStart="@dimen/setup_list_item_padding">

        <EditText
            android:id="@+id/guidedactions_item_title"
            style="@style/Setup.Action.TextInput"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
	    	android:focusable="true"
	    	android:gravity="center_vertical"
            android:imeOptions="actionNext|flagNoExtractUi"
            android:inputType="text">
        </EditText>
    </FrameLayout>

    <CheckBox
        android:id="@+id/password_checkbox"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="@dimen/setup_obfuscation_margin_start"
        android:layout_marginTop="@dimen/setup_obfuscation_margin_top"
        android:buttonTint="@color/setup_list_item_background_focused"
        android:buttonTintMode="src_in"
        android:text="@string/text_obfuscation_toggle_caption" />
</LinearLayout>

        @Override
        public GuidedActionsStylist onCreateActionsStylist() {
            return new GuidedActionsStylist() {
                @Override
                public void onBindViewHolder(ViewHolder vh, GuidedAction action) {
                    super.onBindViewHolder(vh, action);
                    if (action.getId() == GuidedAction.ACTION_ID_CONTINUE) {
                        PasswordViewHolder viewHolder = (PasswordViewHolder) vh;
                        mTextInput = (EditText) viewHolder.getTitleView();
						mTextInput.setClickable(true);
						mTextInput.setFocusableInTouchMode(true);
                        mCheckBox = viewHolder.mCheckbox;
                        mCheckBox.setOnClickListener(view -> {
                            updatePasswordInputObfuscation();
                            EnterPasswordFragment.this.openInEditMode(action);
                        });
                        mCheckBox.setChecked(mUserChoiceInfo.isPasswordHidden());
                        updatePasswordInputObfuscation();
                        openInEditMode(action);
                    }
                }
             }
			@Override
            public int onProvideItemLayoutId() {
                return R.layout.setup_password_item;
            }
         }

增加
mTextInput.setClickable(true);
mTextInput.setFocusableInTouchMode(true);

编译,解决!


另一种尝试
在这之前,尝试过在XML中设置:

        <EditText
            android:clickable="true"
			android:focusableInTouchMode="true"
		>

结果:无效??
反复确认了layout文件的正确性无果。
从代码中去一个个追查并不现实,取了个巧,自定一个EditText替换了默认的,并重写了setClickable函数,从中打印出调用的堆栈得知,在GuidedActionsStylist.onBindViewHolder中确实调用了。

GuidedActionsStylist 位于androidx中,

packages/apps/TvSettings/Settings/Android.mk

LOCAL_PACKAGE_NAME := TvSettings
LOCAL_PRIVATE_PLATFORM_APIS := true
LOCAL_CERTIFICATE := platform
LOCAL_MODULE_TAGS := optional
LOCAL_PROGUARD_FLAG_FILES := proguard.cfg
LOCAL_PROGUARD_ENABLED := disabled

LOCAL_PRIVILEGED_MODULE := true

LOCAL_STATIC_ANDROID_LIBRARIES := \
    androidx.recyclerview_recyclerview \
    androidx.preference_preference \
    androidx.appcompat_appcompat \
    androidx.legacy_legacy-preference-v14 \
    androidx.leanback_leanback-preference \
    androidx.leanback_leanback \
    androidx.lifecycle_lifecycle-extensions \
    androidx-constraintlayout_constraintlayout \

对应的jar包路径:

out/target/common/obj/JAVA_LIBRARIES/androidx.leanback_leanback_intermediates/classes.jar

顺便看下源码:

GuidedActionsStylist.java

		public ViewHolder(@NonNull View v, boolean isSubAction) {
            super(v);

            mContentView = v.findViewById(R.id.guidedactions_item_content);
            mTitleView = (TextView) v.findViewById(R.id.guidedactions_item_title);
            mActivatorView = v.findViewById(R.id.guidedactions_activator_item);
            mDescriptionView = (TextView) v.findViewById(R.id.guidedactions_item_description);
            mIconView = (ImageView) v.findViewById(R.id.guidedactions_item_icon);
            mCheckmarkView = (ImageView) v.findViewById(R.id.guidedactions_item_checkmark);
            mChevronView = (ImageView) v.findViewById(R.id.guidedactions_item_chevron);
            mIsSubAction = isSubAction;

            v.setAccessibilityDelegate(mDelegate);
        }
    /**
     * Binds a {@link ViewHolder} to a particular {@link GuidedAction}.
     * @param vh The view holder to be associated with the given action.
     * @param action The guided action to be displayed by the view holder's view.
     * @return The view to be added to the caller's view hierarchy.
     */
    public void onBindViewHolder(ViewHolder vh, GuidedAction action) {
        vh.mAction = action;
        if (vh.mTitleView != null) {
            vh.mTitleView.setInputType(action.getInputType());
            vh.mTitleView.setText(action.getTitle());
            vh.mTitleView.setAlpha(action.isEnabled() ? mEnabledTextAlpha : mDisabledTextAlpha);
            vh.mTitleView.setFocusable(false);
            vh.mTitleView.setClickable(false);
            vh.mTitleView.setLongClickable(false);
            if (BuildCompat.isAtLeastP()) {
                if (action.isEditable()) {
                    vh.mTitleView.setAutofillHints(action.getAutofillHints());
                } else {
                    vh.mTitleView.setAutofillHints((String[]) null);
                }
            } else if (VERSION.SDK_INT >= 26) {
                // disable autofill below P as dpad/keyboard is not supported
                vh.mTitleView.setImportantForAutofill(View.IMPORTANT_FOR_AUTOFILL_NO);
            }
        }
		//....
    }

从上面的代码可以看出,使用了GuidedActionsStylist后,guidedactions_item_title这个ID的控件会被置为不可点击。
刚好就是前面提及的文本输入框,对头!

引用

android:focusable和android:focusableInTouchMode的区别
GuidedActionsStylist
AndroidX GitHub
AOSP AndroidX Contribution Guide文章来源地址https://www.toymoban.com/news/detail-579049.html

到了这里,关于Android TvSettings Bug: 密码框无法点击唤起输入法的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 前端 解决input框被禁用后无法添加点击事件的bug 简单易懂,快来围观

    在开发中,我们经常会遇到需要禁用input框的情况,但是禁用后无法添加点击事件的问题。这个问题可能会让你感到十分困扰,但是不用担心,本文将会为您介绍一种解决这个问题的方法。 解决方法很简单,只需要在input框的父节点view中添加 style=\\\"pointer-events:none\\\" 即可。具体

    2024年02月10日
    浏览(20)
  • Android12(S)授权弹窗被悬浮窗遮挡导致无法点击问题分析

    在测试过程中发现,部分情况下当应用请求权限时,权限授予弹窗中的选项无法点击,有时候又可以。点击其他区域发现是可以正常响应,获取按键事件,发现触摸是有正常上报事件的,所以可以排除是触摸失灵导致。 既然是权限授予弹窗无法点击,那么我们就去找权限管理

    2024年02月11日
    浏览(18)
  • mac 删除自带的ABC输入法保留一个搜狗输入法,搜狗配置一下可以减少很多的敲击键盘和鼠标点击次数

    对于开发者来说,经常被中英文切换输入法所困扰,我这边有一个方法,删除mac默认的ABC输入法 仅仅保留搜狗一个输入法,配置一下搜狗输入:哪些指定为英文输入,哪些指定为中文输入(符号也可以指定) 重启系统,按住 Command + R 进入恢复模式。 点击顶部菜单栏 实用工

    2024年02月15日
    浏览(20)
  • 微信小程序chooseImage无法唤起选择弹框

    用uniapp打包发布的H5,在浏览器、开发者工具、IOS和部分安卓里都正常,但在微信小程序原生的web-view里,鸿蒙系统下无法唤起选择弹框(之前是可以的,最近鸿蒙更新了一下2.0.0.230就不行了)。无论是使用uni.chooseImage、还是uni-file-picker,都没反应。 原因:无论是chooseImage还是

    2024年02月05日
    浏览(34)
  • 【微信小程序】wx.requestSubscribeMessage无法唤起小程序订阅弹窗

    报错信息: requestSubscribeMessage:fail can only be invoked by user TAP gesture. 报错原因:在某个场景的方法里面调用而不是直接通过用户点击 解决方法:一般可做成显示一个弹框友好的提示用户,然后再让用户点击按钮去手动触发订阅

    2024年02月12日
    浏览(21)
  • uniapp无法唤起相机的避坑之旅(安卓10以上,以及鸿蒙手机

    相机权限:都获取到了。 原因可能是安卓的原生问题,应该在安卓的manifest里添加provider provider android:name=“io.dcloud.common.util.DCloud_FileProvider” android:authorities=“${apk.applicationId}.dc.fileprovider” android:exported=“false” android:grantUriPermissions=“true” meta-data android:name=“android.support.

    2024年04月13日
    浏览(51)
  • 手机显示此应用专为旧版android打造,因此可能无法运行,点击应用后闪退的问题解决方案

    如果您在尝试安装并运行一个Android应用(APK文件)时遇到错误消息“此应用专为旧版Android打造, 因此可能无法运行”,或者应用在启动时立即崩溃,以下是一些您可以尝试的解决步骤: 图片来源:手机显示此应用专为旧版android打造,因此可能无法运行,点击应用后闪退的问题

    2024年01月21日
    浏览(38)
  • linux安装搜狗输入法后无法输入中文

    linux安装sogou输入法参考官网教程,https://shurufa.sogou.com/linux/guide 如下图所示,安装后可以在右上角状态栏看到sogou输入法,但是只能输入英文,无法输入中文。 解决方法如下:

    2024年02月13日
    浏览(36)
  • KBLAutoSwitch偶尔无法自动切换输入法的问题

    KBLAutoSwitch(https://github.com/flyinclouds/KBLAutoSwitch)是一款中英文输入法自动切换软件,但是在使用过程中偶尔会出现无法自动切换成自己想要的输入法的问题,比如我将cmd窗口设为自动切换英文输入法,但是在使用过程中如果当前没有cmd窗口,而是从开始菜单直接创建一个窗口

    2024年02月16日
    浏览(14)
  • win11输入法无法使用解决方案

           最近升级win11之后,经常出现输入法无法使用情况,网上常见的操作方法似乎并无效果。针对这一现象,预判应该是win11目前还未正式发布,存在输入适配的问题,期待后续微软能够妥善尽快解决。       废话不多说,直接上干货。       第1种方法 :       1、Win

    2024年02月05日
    浏览(25)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包