Customize the titlebar layout of the android title bar)

Source: Internet
Author: User
Many users find that the title bar of their android Program
Titlebar area is monotonous. If you want to personalize it, you can use the following method to customize a layout file for the title of your software, such as the title bar of your browser.
Favicon, custom progress bar, and uncertain progress indicators. The following code is used in oncreate, and the sequence should not be changed; otherwise, it cannot be generated.
Effect: requestwindowfeature (window. feature_custom_title );
Setcontentview (R. layout. Main); // layout of the software Activity
Getwindow (). setfeatureint (window. feature_custom_title, R. layout. titlebar); // titlebar is the layout of its own title bar. Although you can customize the title bar to a certain extent, the height and background of the title bar cannot be changed here (two very ugly borders are displayed at both ends after the background is set ). it is said that the reason is inherent in Android. here is the modification method: the principle is like this. adding a title directly as in the code above only adds a sub-interface to the original title without changing the original attributes, such as the title bar size and title bar background. these need to be defined in theme topics. therefore, define a style first. If you modify the background, modify Android: windowtitlebackgroundstyle. If you modify the title bar height, modify Android: windowtitlesize. Example: <? XML version = "1.0" encoding = "UTF-8"?>
<Resources xmlns: Android = "http://schemas.android.com/apk/res/android">
<Style name = "customwindowtitlebackground">
<Item name = "Android: background" >#565656 </item>
</Style>
<Style name = "test" parent = "Android: Theme">
<Item name = "Android: windowtitlesize"> 50dp </item>
<Item name = "Android: windowtitlebackgroundstyle"> @ style/customwindowtitlebackground </item>
</Style>
</Resources> Add the property Android: theme = "@ style/test" to the corresponding activity in the android manifest. xml file of the program. <? XML version = "1.0" encoding = "UTF-8"?>
<Manifest xmlns: Android = "http://schemas.android.com/apk/res/android"
Package = "com. Guardian"
Android: versioncode = "1"
Android: versionname = "1.0" type = "codeph" text = "/codeph">
<Application Android: icon = "@ drawable/icon" Android: Label = "@ string/app_name">
<Activity Android: Name = ". Guardian"
Android: Label = "@ string/app_name"
Android: theme = "@ style/test" // here
>
<Intent-filter>
<Action Android: Name = "android. Intent. Action. Main"/>
<Category Android: Name = "android. Intent. Category. launcher"/>
</Intent-filter>
</Activity>

</Application>
<Uses-SDK Android: minsdkversion = "4"/>

</Manifest> then, you can customize the title bar layout by setting the custom title bar XML file.

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.