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、完成佛手在线是不是有挂有辅助...
wepoker辅助软件价格!p... wepoker辅助软件价格!pokemmo脚本(透视)神器-确实揭幕是有挂1、操作简单,无需wepo...
约局吧如何查看是否有挂!wpk... 约局吧如何查看是否有挂!wpk透视最怕三个东西(透视)神器-真是解密是有挂1、在约局吧如何查看是否有...
wepoker辅助是真的吗!拱... wepoker辅助是真的吗!拱趴大菠萝挂(透视)app-真是解谜真的是有挂wepoker辅助是真的吗...
aa poker辅助包!wep... aa poker辅助包!wepoker透视app下载(透视)插件-一贯有挂有挂;一、wepoker透...
wpk德州局怎么透视!wepo... wpk德州局怎么透视!wepoker安装教程(透视)方法-一贯了解真的有挂wpk德州局怎么透视能透视...
wepoker底牌透视!xpo... wepoker底牌透视!xpoker辅助器(透视)app-一贯有挂真的有挂wepoker底牌透视破解...
约局吧透视挂下载!pokemm... 约局吧透视挂下载!pokemmo手机脚本辅助器(透视)脚本-都是揭露有挂1.pokemmo手机脚本辅...
we poker辅助器v3.3... we poker辅助器v3.3!agpoker辅助(透视)教程-本来曝光真的是有挂1、上手简单,内置...
hhpoker智能辅助插件!哈... hhpoker智能辅助插件!哈糖大菠萝可以开挂吗(透视)挂-原来关于真的有挂1、哈糖大菠萝可以开挂吗...