如何假装在 android kotlin 中点击 tabLayout?
How to pretend a click on tabLayout in android kotlin?
是否可以使用不使用 "real action" 的代码在 tanLayout 上执行子点击?
像 tab[position].performClick()
这样的东西?
有这样的东西吗?
问候
您可以使用以下代码 select 选项卡:
tabs.getTabAt(1)?.select()
希望对您有所帮助!!
你可以使用这样的东西。
public static void onClickTab(TabLayout tab_layout) {
ViewGroup vg = (ViewGroup) tab_layout.getChildAt(0);
int tabsCount = vg.getChildCount();
for (int j = 0; j < tabsCount; j++) {
ViewGroup vgTab = (ViewGroup) vg.getChildAt(j);
int tabChildesCount = vgTab.getChildCount();
for (int i = 0; i < tabChildesCount; i++) {
View tabViewChild = vgTab.getChildAt(i);
if (tabViewChild instanceof TextView) {
((TextView) tabViewChild).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// Perfor your click acrtion
}
});
}
}
}
}
如果您使用带有选项卡布局的视图寻呼机,则只需使用
mViewPager.setCurrentItem(position)
或者如果不使用 viewpager 则使用
mTabLayout.getTabAt(position).select();
是否可以使用不使用 "real action" 的代码在 tanLayout 上执行子点击?
像 tab[position].performClick()
这样的东西?
有这样的东西吗?
问候
您可以使用以下代码 select 选项卡:
tabs.getTabAt(1)?.select()
希望对您有所帮助!!
你可以使用这样的东西。
public static void onClickTab(TabLayout tab_layout) {
ViewGroup vg = (ViewGroup) tab_layout.getChildAt(0);
int tabsCount = vg.getChildCount();
for (int j = 0; j < tabsCount; j++) {
ViewGroup vgTab = (ViewGroup) vg.getChildAt(j);
int tabChildesCount = vgTab.getChildCount();
for (int i = 0; i < tabChildesCount; i++) {
View tabViewChild = vgTab.getChildAt(i);
if (tabViewChild instanceof TextView) {
((TextView) tabViewChild).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// Perfor your click acrtion
}
});
}
}
}
}
如果您使用带有选项卡布局的视图寻呼机,则只需使用
mViewPager.setCurrentItem(position)
或者如果不使用 viewpager 则使用
mTabLayout.getTabAt(position).select();