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

相关内容

热门资讯

信息共享!hhpoker辅助挂... 信息共享!hhpoker辅助挂是真的吗(辅助挂)确实是真的有挂(有挂方略辅助插件)1)免费钻石:进一...
实测交流!wpk真的有透视嘛(... 实测交流!wpk真的有透视嘛(辅助挂)总是真的是有挂(今日头条辅助脚本)1、用户打开应用后不用登录就...
实测交流!wpk真的有透视嘛(... 实测交流!wpk真的有透视嘛(辅助挂)总是真的是有挂(今日头条辅助脚本)1、进入到是否有挂之后,能看...
实测必看!hhpoker是真的... 实测必看!hhpoker是真的吗(辅助挂)切实真的有挂(的确有挂辅助技巧)1、免费脚本咨询教程、免费...
玩家必看教程!wepoker底... 玩家必看教程!wepoker底牌透视(辅助挂)一贯是有挂(了解有挂辅助方法)1、超多福利:超高返利,...
实测交流!wepoker是不是... 实测交流!wepoker是不是有人用挂(辅助挂)果然有挂(确实有挂辅助器)1、起透看视 辅助软件价格...
玩家必看科普!菠萝辅助器免费版... 玩家必看科普!菠萝辅助器免费版的特点(辅助挂)一贯是真的有挂(确实有挂辅助插件)1、该软件可以轻松地...
三分钟了解!hhpoker视频... 三分钟了解!hhpoker视频巡查真的假的(辅助挂)总是真的有挂(有挂攻略辅助教程)1、三分钟了解!...
重要通知!wepoker破解器... 重要通知!wepoker破解器(辅助挂)果然存在有挂(有人有挂辅助插件);1、完成有辅助插件,帮助玩...
重大消息!wepoker软件靠... 重大消息!wepoker软件靠谱么(辅助挂)一贯真的有挂(有挂方式辅助攻略)1、玩家可以在透视最简单...