Customize the titlebar layout of the android title bar

Source: Internet
Author: User
Customize the titlebar layout of the android title bar Many users find that their androidProgramThe titlebar area of the title bar is monotonous. If you want to personalize the title bar, you can use the following method for the title of your software. Customizes a layout file, For example, the browser title bar contains the favicon of the website, custom progress bars, and uncertain progress indicators, Control the implementation method by yourself. BelowCodeInOncreateUsed in, At the same time, do not change the order, otherwise it will not take effect:
Requestwindowfeature (window. feature_custom_title); setcontentview (R. layout. Main );//Software activity LayoutGetwindow (). setfeatureint (window. feature_custom_title,R. layout. titlebar);//Titlebar is the layout of its own title bar

Create titlebar. XML in layout:

<? XML version = "1.0" encoding = "UTF-8"?> <Linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android" Android: layout_width = "Fill_parent" Android: layout_height = "Wrap_content" Android: layout_gravity = "Center_vertical" Android: Orientation = "Horizontal"> < Button Android: ID = "@ + ID/back" Android: layout_width = "Wrap_content" Android: layout_height = "Wrap_content" Android: Text = "@ String/back" Android: textsize = "18sp" Android: textcolor = "# Ff0000ff"/> < Textview Android: layout_width = "Wrap_content" Android: layout_height = "Wrap_content" Android: Text = "@ String/share" Android: textsize = "18sp" Android: textcolor = "# Ffffff00"/> </linearlayout>

 

In this way, the title bar can be customized to a certain extent. However, the height and background of the title bar cannot be changed here (after the background is set, there will be two It is said that the reason is inherent in Android. Here is the modification method: The principle is as follows. Adding a title just like the code above adds a subinterface to the original title without changing the original attributes, For example, the title bar size and background must be defined in the theme topic. Therefore, define a style first. If you modify the background, modify Android: windowtitlebackgroundstyle. To 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>

 

In the android manifest. xml file of the program: Add property Android: theme = "@ style/test" to activity"You can.
<? 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"> <application Android: icon = "@ drawable/icon" Android: Label = "@ string/app_name"> <activity Android: Name = ". Guardian" Android: Label = "@ String/app_name" Android: Theme = "@ Style/test" //  This is where > <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.  

  From: http://www.blogjava.net/Green-nut/articles/332617.html
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.