gpt4 book ai didi

java - Android TabLayout 点击事件

转载 作者:行者123 更新时间:2023-11-30 00:41:47 26 4
gpt4 key购买 nike

我在 TabLayout 中有几个选项卡。 XML:

      <android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
app:tabMode="scrollable">

<android.support.design.widget.TabItem
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="@+id/info_tab"
android:icon="@drawable/info"
android:clickable="true"/>
...

我对如何为这些设置 OnClickListener 感到非常困惑。所有在线资源都假定我使用的是 TabHost,但这些功能不适用于 TabLayout。我应该改用 TabHost 吗?或者 TabLayout 的 OnClickListener 是什么样的?

谢谢!

最佳答案

你可以用这个...

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


}

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

}

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

}
});

并且在 onTabSelected 中,您可以编写代码使用户在单击该选项卡名称时转到该 fragment ..:)

关于java - Android TabLayout 点击事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42463137/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com