2013-12-09 24 views
0

我已經內置自定義選項卡只能與圖片,現在我需要這個標籤圖像時,用戶交換機從阿拉伯語\英語從另一個活動按鈕,如何更改標籤圖片(未按下)?

改變這裏是我的代碼從選項卡活動

標籤
mainTabs = ((TabActivityMy) getParent()).getTabHost(); 
    mainTabs.getTabWidget().setDividerDrawable(null); 
    Intent intent = new Intent(this, c); 
    TabHost.TabSpec spec = mainTabs.newTabSpec(null); 
    View tabIndicator = LayoutInflater.from(this).inflate(R.layout.tab_indicator, ((TabActivityMy) getParent()).getTabHost().getTabWidget(), false); 
    ImageView icon = (ImageView) tabIndicator.findViewById(R.id.icon); 
    icon.setImageResource(drawableId); 
    spec.setIndicator(tabIndicator); 
    spec.setContent(intent); 
    mainTabs.addTab(spec); 

當我做這個應用程序添加新的選項卡,我知道這個代碼是這樣做,但我只需要改變圖像當前所有標籤

enter image description here

+0

http://store1.up-00.com/2013-12/1386590546791.png –

回答

0

一種方法是先刪除從tabhost各方面的意見:從TabWidget

mainTabs = ((TabActivityMy) getParent()).getTabHost(); 
mainTabs.removeAllViews() 

mainTabs.getTabWidget().setDividerDrawable(null); 
Intent intent = new Intent(this, c); 
TabHost.TabSpec spec = mainTabs.newTabSpec(null); 
View tabIndicator = LayoutInflater.from(this).inflate(R.layout.tab_indicator, ((TabActivityMy) getParent()).getTabHost().getTabWidget(), false); 
ImageView icon = (ImageView) tabIndicator.findViewById(R.id.icon); 
icon.setImageResource(drawableId); 
spec.setIndicator(tabIndicator); 
spec.setContent(intent); 
mainTabs.addTab(spec); 

嘗試刪除allviews:

mainTabs.getTabWidget().removeAllViews(); 

有功能:

mainTabs.clearAllTabs(); 

這應該工作你的情況

+0

我也試圖做到這一點,但應用程序崩潰,我認爲應用程序崩潰,因爲我刪除當前視圖也:),對嗎? –

+0

查看編輯後的ans –

+0

嘗試在添加新標籤之前調用clearAllTabs –

0

您可以檢查你的語言交換的價值,並設置基於它的圖像資源..

例如:

if(lamguage==english) 
your_imageView.setImageResource(R.drawable.your_english_image); 
else 
your_imageView.setImageResource(R.drawable.your_arabic_image); 
+0

已經我做,在主標籤活動,但現在我在另一個活動,並有一個按鈕,當我按下它時,在共享偏好中存儲新值並更改自定義操作欄,並且還必須更改標籤圖像,我插入此處的代碼用於將新標籤添加到父,但我只需要更改當前標籤imges –

+0

您是否使用TabHost? –

+0

是的:)我認爲 –