简体   繁体   English

如何检测 android TabLayout 中的选项卡焦点变化?

[英]How can I detect tab focus changes in an android TabLayout?

I have a ViewPager set up with a TabLayout at the top.我在顶部设置了一个 TabLayout 的 ViewPager。 The app is running on a device with physical d-pad directional keys that can be used to move the control focus.该应用程序在具有物理方向键的设备上运行,该方向键可用于移动控制焦点。

How can I detect when the focus is moved to specific tabs in the TabLayout?如何检测焦点何时移动到 TabLayout 中的特定选项卡? I can see the Tab highlight when the focus is received, but I am unable to find any events that might allow me to detect this.当收到焦点时,我可以看到选项卡突出显示,但我找不到任何可能让我检测到这一点的事件。 Also, TabSelected doesn't work, as it doesn't fire until the center key of the d-pad is pressed to "select" the focused tab.此外,TabSelected 不起作用,因为在按下 d-pad 的中心键以“选择”焦点选项卡之前它不会触发。

You can add custom view to your tab, and then setOnFocusChangeListener for this view.您可以将自定义视图添加到您的选项卡,然后为该视图 setOnFocusChangeListener。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android:如何将自定义字体应用于 TabLayout 中的活动选项卡? - Android: How can I apply a custom font to an active tab in TabLayout? 如何在TabLayout中自定义选定的选项卡指示器? - How can I customize the selected tab indicator in a TabLayout? Android:如何查找选项卡布局中哪个选项卡处于活动状态? - Android: How to find which tab is active in a tablayout? 我如何在TabLayout.Tab上添加删除图标以通过单击添加的删除图标来删除选项卡 - How can I add Remove Icon on TabLayout.Tab to delete Tab by clicking added Remove Icon 如何在浏览器选项卡中检测到关闭? - How can I detect a close in the browser tab? AI如何检测mysql的更改? - How can a i detect a mysql changes? Android:如何在选项卡选择上禁用默认的Pop TabLayout动画 - Android: how to disable default pop TabLayout animation on tab selection 如何在Android中以编程方式添加焦点? - How can I add focus programmatically in Android? 如何更改 TabLayout 中选中的选项卡的图标颜色? - How do I change the color of icon of the selected tab of TabLayout? 如何用tablayout制作比例制表符? - How make proportional tab with tablayout?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM