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字符串。

相关内容

热门资讯

玩家必备教程!微乐小程序麻将自... 玩家必备教程!微乐小程序麻将自建房辅助工具插件,微乐自建房脚本免费入口(开挂自建房)软件1、起透看视...
指导大家!微乐自建房辅助工具,... 指导大家!微乐自建房辅助工具,微乐家乡麻将自建房辅助app(开挂自建房)器1)微乐家乡麻将自建房辅助...
实测发现!微乐自建房辅助工具脚... 实测发现!微乐自建房辅助工具脚本,微乐家乡麻将自建房辅助app(开挂自建房)教程1、微乐家乡麻将自建...
科技介绍!微信微乐自建房辅助工... 科技介绍!微信微乐自建房辅助工具,微乐自建房脚本免费入口(开挂自建房)插件1、许多玩家不知道微信微乐...
玩家必看科普!微乐微信自建房辅... 玩家必看科普!微乐微信自建房辅助工具插件,微乐自建房脚本免费入口(开挂自建房)脚本1、金币登录送、破...
最新技巧!微乐家乡麻将自建房辅... 最新技巧!微乐家乡麻将自建房辅助app,微乐小程序免费黑科技(开挂自建房)脚本暗藏猫腻,小编详细说明...
分享开挂内幕!微乐自建房辅助工... 分享开挂内幕!微乐自建房辅助工具免费app,微乐小程序免费黑科技(开挂自建房)技巧一、微乐自建房辅助...
最新技巧!微乐自建房辅助工具免... 最新技巧!微乐自建房辅助工具免费app,微乐小程序免费黑科技(开挂自建房)攻略1、上手简单,内置详细...
每日必备!微乐自建房辅助工具脚... 每日必备!微乐自建房辅助工具脚本,微乐小程序免费黑科技(开挂自建房)器1、微乐自建房辅助工具脚本辅助...
专业讨论!微信微乐自建房辅助工... 专业讨论!微信微乐自建房辅助工具,微乐自建房脚本免费入口(开挂自建房)教程1、金币登录送、破产送、升...