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

相关内容

热门资讯

第六分钟辅助挂!微信闲来辅助神... 第六分钟辅助挂!微信闲来辅助神器app(透视)四川熊猫辅助软件(详细透视外开挂教程)是一款可以让一直...
6分钟辅助挂!兴动互娱辅助脚本... 6分钟辅助挂!兴动互娱辅助脚本(透视)人人燕赵辅助(详细透视外开挂教程);兴动互娱辅助脚本是一种具有...
第7分钟辅助挂!川南小闲辅助器... 1、第7分钟辅助挂!川南小闲辅助器(透视)蜀山四川智能辅助插件(详细透视外开挂教程);代表性(透视辅...
七分钟辅助挂!皮皮游戏挂机辅助... 七分钟辅助挂!皮皮游戏挂机辅助(透视)情怀蒲仙辅助(详细透视外开挂教程)1)皮皮游戏挂机辅助辅助挂:...
第一分钟辅助挂!佛手在线大菠萝... 第一分钟辅助挂!佛手在线大菠萝可以作弊码(透视)胡乐辅助脚本是真的假的(详细透视外开挂教程)1、在佛...
9分钟辅助挂!天天辅助工具(透... 9分钟辅助挂!天天辅助工具(透视)微乐家乡麻辣自建房辅助app(详细透视外开挂教程);致您一封信;亲...
5分钟辅助挂!微乐小程序辅助插... 1、5分钟辅助挂!微乐小程序辅助插件(透视)开心门一番有挂吗(详细透视外开挂教程)。2、微乐小程序辅...
3分钟辅助挂!永久免费脚本辅助... 3分钟辅助挂!永久免费脚本辅助工具(透视)同城游辅助软件(详细透视外开挂教程);永久免费脚本辅助工具...
第一分钟辅助挂!天天爱柳州有没... 1、第一分钟辅助挂!天天爱柳州有没有辅助器(透视)中至赣州黑科技辅助软件视频(详细透视外开挂教程)2...
第五分钟辅助挂!哈糖大菠萝怎么... 第五分钟辅助挂!哈糖大菠萝怎么让系统发好牌(透视)哈灵脚本辅助(详细透视外开挂教程)1、许多玩家不知...