我想为tabLayout的选项卡设置contentDescription,但是talkBack不会读取所选选项卡的内容描述,而只是说“ selected”。我该如何为tabLayout设置contentDescription?
我为每个选项卡更新了viewPager.addOnPageChangeListener中的内容描述,并且我尝试为每个选项卡在tabLayout.addOnTabSelectedListener中设置内容描述,但是它们都不起作用!
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));
}
}
}
我为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) {
}
});