Android's official navigation bar Actionbar (iii) high Imitation Youku homepage

Source: Internet
Author: User

I. Overview of the problem

Through the last two articles, we have a general understanding of how to use Actionbar. In the practical application, we are more custom actionbar, then we need to rewrite or define some styles to modify the Actionbar to meet the specific needs. We take Youku homepage as an example, learn the comprehensive application of Actionbar.

Second, the Android system Actionbar style definition

First of all, we first know how the Android system is defined Actionbar style, here we take the Theme.Holo.Light theme, as an example, through the source we can see in the topic about Actionbar style definition is as follows:

<style name= "Theme.Holo.Light.DarkActionBar" > <item name= "windowcontentoverlay" > @drawable/ab_solid_ shadow_holo</item> <item name= "Actionbarstyle" > @style/widget.holo.light.actionbar.solid.inverse</ item> <item name= "Actionbarwidgettheme" > @style/theme.holo</item> <item name= "ActionBarThem E "> @null </item> <item name=" Actiondropdownstyle "> @style/widget.holo.spinner.dropdown.actionbar </item> <item name= "Actionbuttonstyle" > @style/widget.holo.actionbutton</item> <item nam E= "Actionoverflowbuttonstyle" > @style/widget.holo.actionbutton.overflow</item> <item name= " Actionmodebackground "> @drawable/cab_background_top_holo_dark</item> <item name=" Actionmodesplitbackground "> @drawable/cab_background_bottom_holo_dark</item> <item name=" Actionmodeclosedrawable "> @drawable/ic_cab_done_holo_dark</item> <item Name= "Homeasupindicator" > @drawable/ic_ab_back_holo_dark</item> <item name= "Actionbartabstyle" >@ style/widget.holo.light.actionbar.tabview.inverse</item> <item name= "ActionBarTabBarStyle" > @style/ widget.holo.light.actionbar.tabbar.inverse</item> <item name= "Actionbartabtextstyle" > @style/ widget.holo.light.actionbar.tabtext.inverse</item> <item name= "Actionbardivider" > @drawable/list_ divider_holo_dark</item> <item name= "Actionbaritembackground" > @drawable/item_background_holo_dark </item> <item name= "Actionmenutextcolor" >?attr/textColorPrimaryInverse</item> <item Nam E= "Actionmodestyle" > @style/widget.holo.light.actionmode.inverse</item> <item name= " Actionmodeclosebuttonstyle "> @style/widget.holo.actionbutton.closemode</item> <item name="      Actionmodepopupwindowstyle "> @style/widget.holo.popupwindow.actionmode</item>  <item name= "actionmodecutdrawable" > @drawable/ic_menu_cut_holo_dark</item> <item name= "ActionModeCo Pydrawable "> @drawable/ic_menu_copy_holo_dark</item> <item name=" actionmodepastedrawable ">@ drawable/ic_menu_paste_holo_dark</item> <item name= "actionmodeselectalldrawable" > @drawable/ic_menu_ selectall_holo_dark</item> <item name= "actionmodesharedrawable" > @drawable/ic_menu_share_holo_dark </item> <item name= "actionmodefinddrawable" > @drawable/ic_menu_find_holo_dark</item> <it EM name= "actionmodewebsearchdrawable" > @drawable/ic_menu_search_holo_dark</item></style>

1, Actionbarstyle: This property defines the main styles of Actionbar, including actionbar backgrounds, heading styles, separators, and so on. The specific properties are as follows: TitleTextStyle, background, backgroundsplit, divider. The source code is not posted here, you can view it by yourself.

2, Actionbarsize: Defines the height of the Actoinbar

3, Actionbuttonstyle: Used to define the action item button style, the main properties are background, Paddingstart, Paddingend, MinWidth and so on.

4, Actionbartabstyle: The style used to define the tabs on the Actionbar.

5, Actionbartabbarstyle: The style used to define the strips below the tab.

6, Actionbartabtextstyle: The style used to define the text on the tab.

III. implementation of the case

Below we combine the previous knowledge and the above style step by step to complete the case of this article, Youku homepage.

First, we will hide the title and set the logo, which can be set by the code as follows:

  ActionBar actionbar= Getactionbar ();  Actionbar.setdisplayuselogoenabled (true);  Actionbar.setdisplayshowtitleenabled (false);  Actionbar.setdisplayshowhomeenabled (true);  Actionbar.setdisplayhomeasupenabled (false);  Actionbar.setlogo (R.drawable.icon_youku);

The second step is to complete the tab navigation by following the steps in the previous article, where the code is not posted.

The third step to write the menu file, here is to note that the overflow area menu can not customize the layout, click the overflow overflow menu, I use the Popupwindow implementation. In Popupwindow I added a ListView and added two item layout files for the ListView, one for the login menu and one for the other menu. The following files are listed in the menu file:

 
<menu xmlns:android= "Http://schemas.android.com/apk/res/android" xmlns: tools= "Http://schemas.android.com/tools" tools:context= ".        Mainactivity "> <item android:id=" @+id/action_search "android:icon=" @drawable/btn_game_search " Android:showasaction= "Always" android:title= "search"/> <item android:id= "@+id/action_game" an droid:icon= "@drawable/btn_game_icon" android:orderincategory= "2" android:showasaction= "Always" Androi        d:title= "Game"/> <item android:id= "@+id/action_recommend" android:icon= "@drawable/btn_recommend" android:orderincategory= "3" android:showasaction= "Always" android:title= "market"/> <item an Droid:id= "@+id/action_more" android:icon= "@drawable/btn_more_bg" android:orderincategory= "4" Android: Showasaction= "Always" android:title= "more"/></MENU> 

Menu file, we have all the menu items displayed on the Actionbar.

Here's how to pop up the Popuwindow menu:

        public void Showpopmenu () {//Get status bar height rect frame = new rect ();        GetWindow (). Getdecorview (). Getwindowvisibledisplayframe (frame); To calculate the offset, 50DP sets the height of the Actionbar for us, and by default the tab height and Actionbar are the same int offsety=frame.top+getactionbar (). GetHeight ()-dip2px        (50);        int offsetx=dip2px (10);        View Parentview = Layoutinflater.from (this). Inflate (R.layout.activity_main,null);        View Popview = Layoutinflater.from (this). Inflate (R.layout.pop_layout,null);        ListView myList = (ListView) Popview.findviewbyid (R.id.mylist);        ListAdapter adapter = new ListAdapter (This,initlistdata ());        Mylist.setadapter (adapter);        Popupwindow Popupwindow = new Popupwindow (Popview, dip2px (), viewgroup.layoutparams.wrap_content,true);        Popupwindow.setbackgrounddrawable (New Bitmapdrawable (Getresources (), (BITMAP) null));        Popupwindow.setoutsidetouchable (TRUE); Set the pop-up animation Popupwindow.setanimationstyle (Android. R.style.animation_dialog);       Popupwindow.showatlocation (Parentview, gravity.right| gravity.top,offsetx,offsety);}

Through the above steps, we can achieve the general shape of Youku homepage, but the style is still very far apart, Let's do this with a custom style.

 
<style name= "Apptheme" parent= "Android:Theme.Holo.Light" > <!--Customi Ze your theme here. --<item name= "android:actionbarsize" >50dp</item> <item name= "Android:actionbarstyle" > @style/customactionbarstyle</item> <item name= "Android:actionbuttonstyle" > @style/ customactionbuttonstyle</item> <item name= "Android:actionoverflowbuttonstyle" > @style/ customactionoverflowstyle</item> <item name= "Android:actionbartabstyle" > @style/ customactiontabviewstyle</item> <item name= "Android:actionbartabbarstyle" > @style/ customactiontabbarstyle</item> <item name= "Android:actionbartabtextstyle" > @style/ customactiontabtextstyle</item> <item name= "android:itemtextappearance" > @style/ Customitemtextappearance</item> </style> 

The height of the Actionbar is set by Actionbarsize, and the background of the actionbar is defined by a custom Actionbarstyle, as follows:

<style name= "Customactionbarstyle" parent= "@android: Style/widget.holo.light.actionbar.solid.inverse" >    <item name= "Android:background" > @drawable/actionbar_background</item></style>

By Actionbuttonstyle, the left and right padding and the minimum width are defined.

<style name= "Customactionbuttonstyle" parent= "@android: Style/widget.holo.actionbutton" >        <item name= " Android:paddingleft ">0dip</item>        <item name=" Android:paddingright ">0dip</item>        <item name= "Android:minwidth" >30dip</item></style>

tab-related styles are defined by Actionbartabstyle, Actionbartabbarstyle, and Actionbartabtextstyle.

    <style name= "Customactiontabbarstyle" parent= "@android: Style/widget.holo.actionbar.tabbar" >        <item Name= "Android:background" > @drawable/actionbar_tabview_bg</item>        <item name= "Android: Dividerpadding ">10dp</item>    </style>    <style name=" Customactiontabtextstyle "parent=" @ Android:style/widget.holo.light.actionbar.tabtext ">        <item name=" Android:textsize ">14sp</item >        <item name= "Android:textstyle" >normal</item>        <item name= "Android:textcolor" >@ Color/actionbar_text_color</item>    </style>

  To learn more about the small partners, you can click to view the source code , run the test yourself.

Jerry Education
Source:http://blog.csdn.net/jerehedu
This article is the copyright of Yantai Jerry Education Technology Co., Ltd. and CSDN Common, welcome reprint, but without the author's consent must retain this paragraph statement, and in the article page obvious location to the original link, otherwise reserves the right to pursue legal responsibility.

Android's official navigation bar Actionbar (iii) high Imitation Youku homepage

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.