Android Programming custom title bar (title bar) Sample _android

Source: Internet
Author: User

The example in this article describes the method for Android programming to customize title bar (title bars). Share to everyone for your reference, specific as follows:

Package com.test;
Import android.app.Activity;
Import Android.content.Context;
Import Android.graphics.Canvas;
Import Android.graphics.Color;
Import android.graphics.drawable.Drawable;
Import Android.os.Bundle;
Import Android.view.View;
Import Android.view.Window;
Import android.view.animation.Animation;
Import android.view.animation.TranslateAnimation;
Import Android.widget.ProgressBar;
Import Android.widget.TextView;
  The public class Test extends activity {/** Called when the ' activity is ' A-a-created Boolean customtitlesupported;
    public void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);
    Check if custom title is supported before setting the content view!
    customtitlesupported = Requestwindowfeature (Window.feature_custom_title);
   Setcontentview (R.layout.main);
  Set Custom TitleBar Customtitlebar (GetText (r.string.app_name). ToString (), "Hello world!!"); public void Customtitlebar (string left, string right) {if (Right.lengTh () >) right = right.substring (0, 20); Set up custom title if (customtitlesupported) {GetWindow (). Setfeatureint (Window.feature_custom_title, r.layout.t
  Itle);
  TextView titletvleft = (TextView) Findviewbyid (r.id.titletvleft);
  TextView titletvright = (TextView) Findviewbyid (r.id.titletvright);
  Titletvleft.settext (left);
  Titletvright.settext (right);
  ProgressBar Titleprogressbar;
  Titleprogressbar = (ProgressBar) Findviewbyid (R.id.leadprogressbar);
 Hide the progress bar if it is not needed titleprogressbar.setvisibility (Progressbar.gone);

 }
 }
}

Layout file: Title.xml

 <?xml version= "1.0" encoding= "Utf-8"?> <relativelayout "android:id=" RelativeLayout01 "android:layout_width=" fill_parent "android:layout_height=" fill_parent "xmlns:android=" http:// Schemas.android.com/apk/res/android "> <textview android:layout_width=" wrap_content "android:layout_height=" Wrap_content "android:id=" @+id/titletvleft "android:text=" left "></TextView> <textview android:layout_ Width= "Wrap_content" android:layout_height= "wrap_content" android:id= "@+id/titletvright" android:text= "right"
 Android:layout_alignparentright= "true" ></TextView> <progressbar android:id= "@+id/leadprogressbar" Style= "Android:attr/progressbarstylesmall" android:layout_width= "wrap_content" android:layout_height= "Wrap_ Content "Android:layout_centervertical=" true "android:layout_torightof=" @+id/titletvleft "android:paddingleft=" 3dip "></ProgressBar> </RelativeLayout> 

For more information on Android-related content readers can view the site: "Android View tips Summary", "Android Layout Layout Skills Summary", "Android Development introduction and Advanced Course", " Android Debugging tips and FAQ Solutions Summary, Android Multimedia tips summary (audio, video, audio, etc.), "Android Basic Components Usage Summary" and "Android Control usage Summary"

I hope this article will help you with the Android program.

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.