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、金币登录送、破产送、升...
微乐小程序透视辅助!微乐小程序... 微乐小程序透视辅助!微乐小程序外辅助工具(开挂)攻略-其实揭露真的有挂1、打开软件启动之后找到中间准...
微乐小程序存在有挂!微乐山西威... 微乐小程序存在有挂!微乐山西威信小程序(开挂)工具-总是解密存在有挂1、辅助器安装包、辅助器2、分享...
微乐小程序黑科技免费!微乐家乡... 微乐小程序黑科技免费!微乐家乡脚本助手(开挂)插件-一直解迷存在有挂1、在插件功能辅助器技巧中,中转...
微乐小程序存在有挂!微乐小程序... 微乐小程序存在有挂!微乐小程序破解版修改器(开挂)器-一直普及真的有挂1、这是跨平台的轻量版有透视,...
微乐小程序存在有挂!微信小程序... 微乐小程序存在有挂!微信小程序微乐家乡辅助器(开挂)方法-确实总结是真的挂1、很好的工具软件,可以解...
微乐小程序透视辅助!小程序微乐... 您好,这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302】很多玩家在这款游戏中打...
微乐小程序透视挂!微信小程序微... 微乐小程序透视挂!微信小程序微乐安徽辅助器(开挂)技巧-其实辅助存在有挂1、进入游戏-大厅左侧-新手...
微乐小程序真的有挂!微乐自建房... 微乐小程序真的有挂!微乐自建房辅助多少钱一个月(开挂)挂-确实详细真的是有挂所有人都在同一条线上,像...
微乐小程序存在有挂!微乐自建房... 微乐小程序存在有挂!微乐自建房免费黑科技下载(开挂)攻略-都是分享真的有挂1、免费脚本咨询教程、免费...