Two ways to customize the title bar style in Android _android

Source: Internet
Author: User

The original Android title bar color comparison monotonous, is a black lump, now assume your software needs to add the title bar alone, so not only beautiful but also can be added to the progress bar, how to achieve:

method One , in your activity, add the following code to the OnCreate method:

Requestwindowfeature (window.feature_custom_title);   
Setcontentview (r.layout.main);  The layout of the software activity 
GetWindow (). Setfeatureint (Window.feature_custom_title, R.layout.titlebar); TitleBar for the layout of its own title bar

But the new problem again, this is not the depth of the custom title bar, such as the original height and background have not changed, there is no good way? The answer is yes,

Method Two:

So first define a style, modify the background if you modify the Android:windowtitlebackgroundstyle
If you modify the title bar height, modify the 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>

Adding attributes to the activity in the android_manifest.xml of the program Android:theme = "@style/test" is OK.

<?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= 
    ". Test " 
         android:label=" @string/app_name " 
         android:theme =" @style/test "  //Right here 
         > 
      < intent-filter> 
        <action android:name= "Android.intent.action.MAIN"/> 
        <category "Android.intent.category.LAUNCHER"/> 
      </intent-filter> 
    </activity> 
 
  </ application> 
  <uses-sdk android:minsdkversion= "4"/> 
 
</manifest>

You can then customize the title bar layout by using 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.