How to customize the title bar (titlebar) for the activity in the Android-tabactivity or tabhost container)

Source: Internet
Author: User

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);}}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.