0
我使用選項卡布局與查看傳呼機包含4個選項卡,我的問題是,如何在選項卡上設置onLongClickListener,然後重命名它? 在此先感謝。安卓選項卡布局與查看傳呼機
我使用選項卡布局與查看傳呼機包含4個選項卡,我的問題是,如何在選項卡上設置onLongClickListener,然後重命名它? 在此先感謝。安卓選項卡布局與查看傳呼機
爲onLongClickListener
View tabView= mTabHost.getTabWidget().getChildAt(i);
// set the tag information at the view of the tab (the tag contains the position number of the tab)
tabView.setTag(Integer.valueOf(i));
tabView.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
// TODO Auto-generated method stub
// I print the number position of the tab
Log.d("tab number", ((Integer)view.getTag()).toString());
return false;
}
});
爲重命名選項卡
((TextView)((RelativeLayout)getTabWidget().getChildAt(tabIndex)).getChildAt(textIndex)).setText("NewTabText");
try like this.
private void changeTabsText() {
ViewGroup vg = (ViewGroup) tabLayout.getChildAt(0);
int tabsCount = vg.getChildCount();
for (int j = 0; j < tabsCount; j++) {
ViewGroup vgTab = (ViewGroup) vg.getChildAt(j);
int tabChildsCount = vgTab.getChildCount();
for (int i = 0; i < tabChildsCount; i++) {
View tabViewChild = vgTab.getChildAt(i);
if (tabViewChild instanceof TextView) {
((TextView) tabViewChild).setText("your Text");
}
}
}
}
喜FRND,做這項工作_tablayout_ ... –
請試一試。我希望它能夠正常工作或分享您的代碼,以便我可以嘗試妥善解決此問題。謝謝 – 2016-07-25 04:09:46