AndroidTalkback没有在选项卡列表中宣布选项卡计数。
创始人
2024-08-21 14:30:27
0次

你可以通过在选项卡列表的AppBarLayout或ViewPager中添加AccessibilityDelegateCompat来解决此问题。 在AppbarLayout中,你可以通过访问其子项来获取TabLayout,并获取其子项的个数来报告选项卡的总数。 在ViewPager中,你可以使用PagerAdapter中的getPageTitle()方法获取选项卡标题,以及使用getCount()方法获取选项卡总数。

示例代码:

AppBarLayout:

appBarLayout.setAccessibilityDelegateCompat(new AccessibilityDelegateCompat() {
    @Override
    public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) {
        super.onInitializeAccessibilityNodeInfo(host, info);
        TabLayout tabLayout = (TabLayout) appBarLayout.getChildAt(0);
        if (tabLayout != null) {
            int tabCount = tabLayout.getTabCount();
            info.setContentDescription(getString(R.string.tab_list_description, tabCount));
        }
    }
});

ViewPager:

final ViewPager viewPager = findViewById(R.id.view_pager);
viewPager.setAdapter(new PagerAdapter(getSupportFragmentManager()) {
    @Override
    public int getCount() {
        return 3; // number of tabs
    }

    @Override
    public CharSequence getPageTitle(int position) {
        // tab titles
        switch (position) {
            case 0:
                return getString(R.string.tab_title1);
            case 1:
                return getString(R.string.tab_title2);
            case 2:
                return getString(R.string.tab_title3);
            default:
                return null;
        }
    }
});

viewPager.setAccessibilityDelegateCompat(new AccessibilityDelegateCompat() {
    @Override
    public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) {
        super.onInitializeAccessibilityNodeInfo(host, info);
        int tabCount = viewPager.getAdapter().getCount();
        info.setContentDescription(getString(R.string.tab_list_description, tabCount));
    }
});

在以上示例代码中,getString(R.string.tab_list_description, tabCount)将返回包含选项卡计数的文本。 您需要在strings.xml文件中添加tab_list_description字符串。

相关内容

热门资讯

推荐一款辅助!wepoker免... 本地部署 AI 黑科技工具迎来新版本,不用上传文件到云端就能完成wepoker免费脚本咨询解析、 A...
三分钟了解透视挂!we pok... 三分钟了解透视挂!we poker插件,wepoker外卦神器软件安装(果然是真的有透视挂)AI 是...
带你了解透视挂!德扑圈透视,德... 您好:德扑之星透视这款游戏可以开挂的,确实是有挂的,很多玩家在这款游戏中打牌都会发现很多用户的牌特别...
总算清楚透视挂!wepoker... 您好:wepoker软件靠谱么这款游戏可以开挂的,确实是有挂的,很多玩家在这款游戏中打牌都会发现很多...
我来教大家辅助器!wepoke... 我来教大家辅助器!wepoker辅助脚本,微扑克是如何开挂的教程(原本存在有辅助器)AI 是一款可以...
一秒答解透视!wepoker透... 很多人使用云端 AI 时,都担心wepoker透视有没有、内部资料上传带来隐私风险。这款本地运行的 ...
专业讨论!辅助挂!wepoke... AI 黑科技赛道又上新,这款智能处理工具堪称效率开挂,专门面向短视频创作者打造。它打通脚本撰写、AI...
记者爆料开挂!德普之星透视辅助... 记者爆料开挂!德普之星透视辅助插件,wepoker开挂技巧插件(竟然真的是有开挂)主打本地运行的 A...
一分钟带你了解透视挂!we p... 您好:we poker辅助器下载这款游戏可以开挂的,确实是有挂的,很多玩家在这款游戏中打牌都会发现很...
一分钟教你辅助器!wpk俱乐部... 很多人使用云端 AI 时,都担心wpk俱乐部是真的吗、内部资料上传带来隐私风险。这款本地运行的 AI...