Common top headings and returned titlebar in the project

Source: Internet
Author: User

1. Define the layout file and create a new title_bar_view.xml under layout

<?XML version= "1.0" encoding= "Utf-8"?><Relativelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Match_parent"Android:layout_height= "48DP"Android:background= "@drawable/bg_top_bar" >    <ImageViewAndroid:id= "@+id/bar_back"Android:layout_width= "48DP"Android:layout_height= "48DP"Android:scaletype= "Center"android:src= "@drawable/btn_back_selector" />    <TextViewAndroid:id= "@+id/bar_title"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Android:layout_alignparenttop= "true"Android:layout_centerhorizontal= "true"Android:layout_marginleft= "48DP"Android:layout_marginright= "48DP"android:gravity= "Center"Android:text= "Title"Android:textcolor= "#FFFFFFFF"android:textsize= "24SP"Android:textstyle= "normal" />    <TextViewAndroid:id= "@+id/bar_action"Android:layout_width= "48DP"Android:layout_height= "48DP"Android:layout_alignparentright= "true"android:layout_centervertical= "true"android:gravity= "Center"Android:text= "Action"Android:textcolor= "#FFFFFFFF"android:textsize= "18SP"Android:textstyle= "normal"android:visibility= "Gone" /></Relativelayout>

Related resources, create a new btn_back_selector.xml under drawable

<?XML version= "1.0" encoding= "Utf-8"?><selectorxmlns:android= "Http://schemas.android.com/apk/res/android">    <Itemandroid:drawable= "@drawable/action_button_back_pressed"android:state_pressed= "true"/>    <Itemandroid:drawable= "@drawable/action_button_back_normal"/></selector>

2. Custom view inherits from Relativelayout

 Public classTitleBarextendsrelativelayout{PrivateImageView Ivback; PrivateTextView Tvtitle; PrivateTextView tvaction;  PublicTitleBar (Context context) { This(Context,NULL); }     PublicTitleBar (Context context, AttributeSet attrs) {Super(context, attrs); View View= View.inflate (Context, R.layout.title_bar_view, This); Ivback=(ImageView) View.findviewbyid (r.id.bar_back); Tvtitle=(TextView) View.findviewbyid (r.id.bar_title); Tvaction=(TextView) View.findviewbyid (r.id.bar_action); }     Public voidSetbackvisibility (Booleanshow) {ivback.setvisibility (show?View.VISIBLE:View.INVISIBLE); }     Public voidSettitle (String title) {Tvtitle.settext (title); }         PublicImageView Getivback () {returnIvback; }     Public voidSetivback (ImageView ivback) { This. Ivback =Ivback; }     PublicTextView Gettvtitle () {returnTvtitle; }     Public voidSettvtitle (TextView tvtitle) { This. Tvtitle =Tvtitle; }     PublicTextView gettvaction () {returntvaction; }     Public voidsettvaction (TextView tvaction) { This. tvaction =tvaction; }}

Common top headings and returned titlebar in the project

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.