Effect:
1. Customize the titlebar layout.
<? XML version = "1.0" encoding = "UTF-8"?>
<Relativelayout xmlns: Android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "match_parent"
Android: layout_height = "match_parent">
<Textview
Android: Id = "@ + ID/TV _songscount"
Android: layout_width = "70dp"
Android: layout_height = "wrap_content"
Android: layout_alignparentleft = "true"
Android: layout_centervertical = "true"
Android: layout_marginleft = "10dp"
Android: singleline = "true"
Android: text = "2222"
Android: textcolor = "# fffff0"
Android: textstyle = "bold"/>
<Textview
Android: Id = "@ + ID/TV _title"
Android: layout_width = "match_parent"
Android: layout_height = "wrap_content"
Android: layout_centervertical = "true"
Android: gravity = "center"
Android: text = "hahahahaha"
Android: textcolor = "# 3a3a3a"
Android: textsize = "20sp"/>
<Imagebutton
Android: Id = "@ + ID/imgbtn_toplay"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: layout_alignparentright = "true"
Android: layout_centervertical = "true"
Android: layout_marginright = "10dp"
Android: Background = "@ null"
Android: contentdescription = "ppppme"
Android: src = "@ drawable/BTN"/>
</Relativelayout>
2. Load the layout in. java.
Private void inittitlebar (){
Getwindow (). setfeatureint (window. feature_custom_title,
R. layout. titlebar );
}
3. Call inittitlebar
@ Override
Protected void oncreate (bundle savedinstancestate ){
Super. oncreate (savedinstancestate );
// Declare to use the custom title requestwindowfeature (window. feature_custom_title); setcontentview (R. layout. activity_main );
Inittitlebar ();
}
Wang Liping -- custom titlebar