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

相关内容

热门资讯

第2分钟辅助!wepoker私... 第2分钟辅助!wepoker私人局辅助,wepoker作弊视频,举措教程(有挂技巧)1、第2分钟辅助...
第6分钟辅助!德普之星辅助器,... 第6分钟辅助!德普之星辅助器,德州透视插件,资料教程(有挂总结)1、在德普之星辅助器插件功能辅助器技...
第二分钟辅助!wepoker免... 第二分钟辅助!wepoker免费透视,wepoker免费透视,举措教程(有挂解密)1、许多玩家不知道...
第7分钟辅助!hhpoker真... 第7分钟辅助!hhpoker真的有透视吗,wpk辅助软件,法门教程(有挂透视);所有人都在同一条线上...
2分钟辅助!hhpoker辅助... 2分钟辅助!hhpoker辅助挂是真的吗,wepoker透视脚本免费,举措教程(有挂头条)1、hhp...
8分钟辅助!智星德州插件怎么下... 8分钟辅助!智星德州插件怎么下载,poker world辅助,妙招教程(有挂助手)1、下载好智星德州...
三分钟辅助!wepokerpl... 三分钟辅助!wepokerplus透视脚本免费,拱趴大菠萝万能挂图解,总结教程(真是有挂)1、超多福...
2分钟辅助!wepoker国外... 2分钟辅助!wepoker国外版透视,智星德州辅助译码插件靠谱吗,秘籍教程(了解有挂)1、超多福利:...
4分钟辅助!德州局透视脚本,w... 4分钟辅助!德州局透视脚本,wepoker私人局外卦,指南书教程(有挂辅助)亲,关键说明,wepok...
第5分钟辅助!约局吧德州有挂吗... 第5分钟辅助!约局吧德州有挂吗,拱趴大菠萝挂,资料教程(有挂秘笈)1、下载好约局吧德州有挂吗脚本下载...