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、微乐家乡麻将自建房...
一分钟了解!微信微乐自建房辅助... 一分钟了解!微信微乐自建房辅助工具,微乐小程序免费黑科技(开挂自建房)攻略1)微信微乐自建房辅助工具...
我来教教大家!微乐自建房辅助工... 我来教教大家!微乐自建房辅助工具挂,微乐自建房脚本免费入口(开挂自建房)方法1)微乐自建房辅助工具挂...
指导大家!微乐自建房辅助工具神... 指导大家!微乐自建房辅助工具神器,微乐家乡麻将自建房辅助app(开挂自建房)器1、完成微乐家乡麻将自...
我来分享!微乐小程序麻将自建房... 我来分享!微乐小程序麻将自建房辅助工具插件,微乐自建房脚本免费入口(开挂自建房)工具1、金币登录送、...
科普分享!微乐自建房辅助工具,... 科普分享!微乐自建房辅助工具,微乐小程序免费黑科技(开挂自建房)app微乐自建房辅助工具辅助器是一种...
2024教程!微乐家乡麻将自建... 2024教程!微乐家乡麻将自建房辅助app,微乐自建房脚本免费入口(开挂自建房)软件微乐家乡麻将自建...
重大发现!微乐自建房辅助工具挂... 重大发现!微乐自建房辅助工具挂,微乐小程序免费黑科技(开挂自建房)软件1、点击下载安装,微乐自建房辅...
玩家必看!微乐小程序自建房辅助... 玩家必看!微乐小程序自建房辅助工具插件,微乐自建房脚本免费入口(开挂自建房)软件1、微乐小程序自建房...