[英]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.