android - 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) {
}
});
解决方案
推荐阅读
- php - 从程序将数据保存或存储在数据库中
- flutter - Flutter ListWheelScrollView
- android - 从与 FileProvider 共享大 pdf 文件的电子邮件客户端返回后,onCreate 被调用
- html - div 被放在上面的 div 中
- jsp - 为什么会话在我的 JSP 页面中返回 null?
- powershell - CSV 为空以导出广告用户的自定义属性
- runtime-error - 打开 SAP 时出现“nwbc.exe 已停止工作”错误
- c# - 在图片框中查找和显示图像
- ios - swift 4中的标签栏活动
- signal-processing - 使用捕获的信号和噪声的 PSD 计算 SNR