首页 > 解决方案 > set contentDescription for tabLyaout

问题描述

I want to set contentDescription for tabs of tabLayout but talkBack doesn't read the content description of the tab that is selected and it just say 'selected'. How do I have to set contentDescription for tabLayout?

I update content description in viewPager.addOnPageChangeListener for each tabs and also I tried to set content description in tabLayout.addOnTabSelectedListener for each tabs but none of them worked!

 tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
                @Override
                public void onTabSelected(TabLayout.Tab tab) {
                    updateTabContentDescription();
                }

                @Override
                public void onTabUnselected(TabLayout.Tab tab) {

                }

                @Override
                public void onTabReselected(TabLayout.Tab tab) {

                }
            });

...

private void updateTabContentDescription() {
        for (int i = 0; i < adapter.getCount(); i++) {
            TabLayout.Tab tab = tabLayout.getTabAt(i);
            if (tab != null) {
                tab.setContentDescription(adapter.getPageTitle(i));
            }
        }
    }

and I test it for viewPager:

viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
                @Override
                public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

                }

                @Override
                public void onPageSelected(int position) {
                    updateTabContentDescription();
                }

                @Override
                public void onPageScrollStateChanged(int state) {

                }
            });

标签: androidandroid-tablayoutandroid-accessibility

解决方案


推荐阅读