Because tabactivity itself has a titlebar, if the activity in the tab still wants to customize the titlebar, it will conflict, because two titlebars ,,
Here we need to hold the reference of tabactivity in the activity in the tab, so that we can dynamically customize the title bar when displaying an activity ..
It should be noted that the title bar is in tabactivity, so if you want to find the button and other objects in the title bar, you will find them through the reference held ,,,
Special attention is to find the title bar object. After customizing the title bar in onresume, that is, loading the titlebar layout into tabactivity, you can find it again. It has been depressing for a long time.
See more custom title bar Methods: http://blog.csdn.net/xixinyan/article/details/6931019
Problem: when switching between different activities, or an activity loses focus due to text input by the user, the button in the title bar does not respond after the input is complete.
Resolving...
Package COM. test; import android. app. tabactivity; import android. content. intent; import android. OS. bundle; import android. view. window; import android. widget. tabhost; public class customtitleintabactivity extends tabactivity {public static customtitleintabactivity mtabactivityinstance;/** called when the activity is first created. * // @ overridepublic void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); requestwindowfeature (window. feature_custom_title); setcontentview (R. layout. main); tabhost = gettabhost (); // The activity tabhosttabhost. tabspec spec; // reusable tabspec for each tabintent; // reusable intent for each tabmtabactivityinstance = This; // create an intent to launch an activity for the tab (to be reused) tabintent = new intent (). setclass (this, Taba. class); // initialize a tabspec for each tab and add it to the tabhostspec = tabhost. newtabspec ("pickridetab "). setindicator ("Car X "). setcontent (tabintent); tabhost. addtab (SPEC); // create an intent to launch an activity for the tab (to be reused) tabintent = new intent (). setclass (this, Tabb. class); // initialize a tabspec for each tab and add it to the tabhostspec = tabhost. newtabspec ("pickridetab "). setindicator ("3 car ride "). setcontent (tabintent); tabhost. addtab (SPEC); tabhost. setcurrenttab (0 );}}
package com.test;import android.app.Activity;import android.os.Bundle;import android.view.Window;public class TabA extends Activity {/** Called when the activity is first created. */@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);// requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);setContentView(R.layout.titilebar_talklist);}@Overrideprotected void onResume() {super.onResume();CustomTitleInTabActivity.mTabActivityInstance.getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.titilebar_talklist);}}
package com.test;import android.app.Activity;import android.os.Bundle;import android.view.Window;public class TabB extends Activity {/** Called when the activity is first created. */@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);// requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);setContentView(R.layout.titilebar_talklist);}@Overrideprotected void onResume() {super.onResume();CustomTitleInTabActivity.mTabActivityInstance.getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.titilebar_talklist2);}}