In the teacher's call, we do the painful code extraction, encapsulation, as long as the same, all to extract, encapsulation.
Ninja World, has a legendary forbearance, even if it is not aware of the patient, he stood in front of you, but you can not see him, when you take lightly, he in your back to give you a fatal blow. He is invisibility.
idea: for a title bar, an app to be used multiple times, we have to extract it separately, as an XML if an interface needs to be included in the Include
<include android:id= "@+id/title_bar" layout= "@layout/layout_title_bar"/>
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "android:id=" @+id/title_bar "android:layout_width=" match_parent "android:layout_height=" 55DP "Android: background= "@drawable/title_red_bg2" android:gravity= "center_vertical" android:orientation= "Horizontal" > < Button android:id= "@+id/btn_left" style= "@style/style_title_btn" android:layout_width= "Wrap_content" Android:background= "@android: Color/transparent" android:layout_height= "Wrap_content" Android:layout_ marginleft= "5DP" android:padding= "5DP" android:text= "/> <imagebutton android:id=" @+id/imgb Tn_left "android:layout_width=" 40DP "android:layout_height=" 40DP "android:layout_marginleft=" 5DP " android:layout_marginright= "5DP" android:background= "@android: color/transparent" android:scaletype= "cent Erinside "/> <relativelayoUT android:layout_width= "0dip" android:layout_height= "Wrap_content" android:layout_weight= "1" > <textview android:id= "@+id/txt_title" style= "@style/style_title" Android:layout_w Idth= "Wrap_content" android:layout_height= "Wrap_content" android:layout_centerinparent= "true" android:drawablepadding= "5DP" android:gravity= "center" android:singleline= "true" and roid:text= "News"/> </RelativeLayout> <imagebutton android:id= "@+id/imgbtn_text" Android : layout_width= "40DP" android:layout_height= "40DP" android:layout_marginleft= "5DP" Android:layout_marg inright= "5DP" android:visibility= "Gone" android:src= "@drawable/icon_textsize" android:background= "@an Droid:color/transparent "android:scaletype=" Centerinside "/> <imagebutton android:id=" @+id/imgbtn_r Ight "Android:layOut_width= "40DP" android:layout_height= "40DP" android:layout_marginleft= "5DP" Android:layout_marginri ght= "5DP" android:background= "@android: Color/transparent" android:scaletype= "Centerinside"/> <Imag Ebutton android:id= "@+id/btn_right" android:layout_width= "40DP" android:layout_height= "40DP" android:layout_marginleft= "5DP" android:layout_marginright= "5DP" android:background= "@android: Color/transpar Ent "android:scaletype=" Centerinside "/></linearlayout>
About the layout. Button ImageView are set to #00000000 transparent color
<span style= "FONT-SIZE:18PX;" > android:background= "@android: Color/transparent" in fact, this title bar does a good job, if you are not suitable for the development of the time, you can hand residual. </span>
And then initialize the Oncreate method.
protected void Inittitlebar (view view) {leftbtn = (Button) View.findviewbyid (r.id.btn_left); rightbtn = (ImageButton) View.findviewbyid (r.id.btn_right); leftimgbtn = (ImageButton) View.findviewbyid (r.id.imgbtn_left); rightimgbtn = ( ImageButton) View.findviewbyid (r.id.imgbtn_right); Leftimgbtn.setimageresource (r.drawable.img_menu); titleTv = ( TextView) View.findviewbyid (r.id.txt_title); leftbtn.setvisibility (View.gone); rightbtn.setvisibility (View.GONE); if (leftimgbtn!=null) Leftimgbtn.setonclicklistener (this);}
Android title bar optimizer (1)--commemorative fire---invisibility