How to change tab node icon after installation? (Android)

I am trying to change the icon of one of the tabs of a tab node at runtime. I can’t figure out what to do with widgets. could anyone let me know how this is done?

 spec = tabHost.newTabSpec("hello").setIndicator("hello",
       res.getDrawable(R.drawable.tab1)).setContent(intent);
 tabHost.addTab(spec)

The xml file looks like this: selector xmlns: android = "http://schemas.android.com/apk/res/android" - If selected, use gray - item android: drawable = "@ drawable / icon1" android: state_selected = " true "/"> - If you have not selected, item android: drawable = "@ drawable / icon1" / Selector

Thanks Titus

+3
source share
1 answer

TabHost ( ). XML, .

View ic = (View) tabHost.getTabWidget().getChildTabViewAt(0).findViewById(android.R.id.icon);
ic.setBackgroundResource(R.drawable.icon_public);

.

+1

Source: https://habr.com/ru/post/1749650/


All Articles