Updating Android Tab Icons

前端 未结 5 1171
广开言路
广开言路 2020-12-08 04:26

I have an activity which has a TabHost containing a set of TabSpecs each with a listview containing the items to be displayed by the tab. When each TabSpec is created, I set

5条回答
  •  感动是毒
    2020-12-08 04:40

    This is what I did and it works for me. I created this function in the activity that extends from TabBarActivity

    public void updateTab(int stringID) {
        ViewGroup identifyView = (ViewGroup)getTabWidget().getChildAt(0);
        TextView v =  (TextView)identifyView.getChildAt(identifyView.getChildCount() - 1);
        v.setText(stringID);
    }
    

    You can modify this function to change the image instead of text or you can change both, also you can modify this to get any tab child. I was particularly interested in modifying the text of the first tab at runtime.

    I called this function from the relevant activity using this call

    getParent().updateTab(R.string.tab_bar_analyze);
    

提交回复
热议问题