Android--Case study accumulation

Source: Internet
Author: User

Theme

Actionbar/toolbar

Android.support.design.widget. Collapsingtoolbarlayout

Android.support.design.widget.AppBarLayout

@, Theme

1. Set Noactionbar

<Resources>    <!--Base application theme. -    <stylename= "Apptheme.base"Parent= "Theme.AppCompat.Light.NoActionBar">        <!--Customize your theme here. -        <Itemname= "Colorprimary">#3F51B5</Item>        <!--Light Indigo -        <Itemname= "Colorprimarydark">#3949AB</Item>        <!--Dark Indigo -        <Itemname= "Coloraccent">#00B0FF</Item>        <!--Blue -    </style>    <stylename= "Apptheme"Parent= "Apptheme.base"></style></Resources>

@, Actionbar/toolbar

1. Theme is set to add to the Noactionbar,layout file

 <  android.support.v7.widget.toolbar  android:id  = "@+id/toolbar"  
   
     Android:layout_width  
    = "Match_parent"  
     Android:layout_height  
    = "? Attr/actionbarsize"  
     Android:background  
    = "? Attr/colorprimary"  
     app:layout_scrollflags  
    = "Scroll|enteralways"  
     App:popuptheme  
    = "@style/themeoverlay.appcompat.light"  
    />  
   

And then set this toolbar to Actionbar in code

 Toolbar Toolbar = (Toolbar) Findviewbyid (R.id.toolbar); Setsupportactionbar (toolbar);  //  set ActionBar  ActionBar        Supportedactionbar = Getsupportactionbar ();  if  (Supportedactionbar! = null  Span style= "color: #000000;" ) { //  Sets the icon to navigate up. The default is the left arrow   Supportedactionbar.sethomeasupindicator (R.drawable.ic_menu_white_            24DP);  //  set whether to display up navigation: True to show, false does not display            ; The default is False.  supportedactionbar.setdisplayhomeasupenabled (true         ); }        

Related knowledge:

A, if the android.r.id.home is not processed in onoptionsitemselected, then: the corresponding activity in Androidmanifest specifies Android: Parentactivityname, return to parentactivity, or do nothing.

b, if it is returned parentactivity, then Parentactivity will OnDestroy, OnCreate, OnStart, Onresume to do it again. And if you press the back key, it's just (OnStart), Onresume. It is important to consider this when you have tab pages for the main interface.

C, in the onoptionsitemselected to judge, if it is Android. R.id.home, the Finishi () is called directly, which can also reach the effect of pressing the return key. Of course, if onbackpressed () does not do special processing, it can also call onbackpressed ().

D, Application scenario: Use this method to add an indicator to the side navigation bar.

@, Android.support.design.widget.CollapsingToolbarLayout

1, the packaging of Tookbar.

2. If the Collaspsingtoolbarlayout app:layout_scrollflags is set to exituntilcollasped, the child control is set App:layout_collapsemode : Pin (fixed, up navigation on toolbar and menu button does not disappear), parallax (move with Collapsingtoolbarlayout, navigation on toolbar and menu button disappears), But the final height and width is the height and width of the toobar.

3, App:contentscrim specified the final display of content.

@, Android.support.design.widget.AppBarLayout

1, child control settings app:layout_scrollflags: Sroll (slide up (scroll bar down), child controls go up together), enteralways (slide up), regardless of whether the scroll bar is sliding to the top, the child controls appear, If you do not specify this value, you will have to wait for the scrollbar to slide to the top, and the child controls will not appear, enteralwayscollasped (what is the use of this test??). ), exituntilcollasped (combined with collapsingtoolbarlayout use if Collapsingtoolbarlayout's toolbar put App:layout_ Collapsemode is set to pin, the up navigation and menu buttons on the toolbar do not disappear.

Example one: Appbarlayout + Toolbar + tablayout, sliding Toolbar hidden, tab label retention

       <Android.support.design.widget.AppBarLayoutAndroid:id= "@+id/appbar"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:theme= "@style/themeoverlay.appcompat.dark.actionbar">            <Android.support.v7.widget.ToolbarAndroid:id= "@+id/toolbar"Android:layout_width= "Match_parent"Android:layout_height= "? Attr/actionbarsize"Android:background= "? Attr/colorprimary"App:layout_scrollflags= "Scroll|enteralways"App:popuptheme= "@style/themeoverlay.appcompat.light" />            <Android.support.design.widget.TabLayoutAndroid:id= "@+id/tabs"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content" />        </Android.support.design.widget.AppBarLayout>    

Example two: Appbarlayout + collapsingtoolbarlayout + Toolbar

    <Android.support.design.widget.AppBarLayoutAndroid:id= "@+id/appbar"Android:layout_width= "Match_parent"Android:layout_height= "256DP"android:fitssystemwindows= "true"Android:theme= "@style/themeoverlay.appcompat.dark.actionbar">        <Android.support.design.widget.CollapsingToolbarLayoutAndroid:id= "@+id/collapsing_toolbar"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:fitssystemwindows= "true"Android:theme= "@style/themeoverlay.appcompat.dark"App:contentscrim= "? Attr/colorprimary"App:expandedtitlemarginend= "72DP"App:expandedtitlemarginstart= "16DP"App:layout_scrollflags= "scroll|exituntilcollapsed">            <ImageViewAndroid:id= "@+id/image"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:fitssystemwindows= "true"Android:scaletype= "Centercrop"App:layout_collapsemode= "Parallax"Tools:background= "@drawable /A"/>            <Android.support.v7.widget.ToolbarAndroid:id= "@+id/toolbar"Android:layout_width= "Match_parent"Android:layout_height= "? Attr/actionbarsize"App:layout_collapsemode= "Parallax"App:popuptheme= "@style/themeoverlay.appcompat.light"/>        </Android.support.design.widget.CollapsingToolbarLayout>    </Android.support.design.widget.AppBarLayout>

Android--Case study accumulation

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.