Android Studio Layout Template One of Floatbutton and toolbar

Source: Internet
Author: User

Starting today to learn the recommended template Android Studio, today's hair should have been sent yesterday, but the students just woke up even the pressure transformer socket did not check directly plugged into the rice cooker, and then overloaded with a day to stop the electricity this big Sunday dorm no electricity ....


This afternoon, I called, and looked at the fur with yesterday's look, on the template knocked out, and added something, also good.


Forget one thing add on add compile ' com.android.support:design:23.2.1 '


The Code section is divided into several major chunks:

1.content_layout.xml This is the main display interface, is the new Hello World. But this layout file is not a layout file associated with the creation of the activity, but rather the layout file is embedded into another layout file.


2.activityu_layout.xml This file is a nested layout file, which is the layout of the main toolbar control and the Floatingactionbutton control, which is important in the layout structure.


3.menu.xml This file is a menu file, mainly for the menu embedded in the toolbar bar.


4.mainactivity.java this is to achieve a variety of monitoring.


First, Content_layout.xml
<?xml version= "1.0" encoding= "Utf-8"? ><relativelayout xmlns:android= "http://schemas.android.com/apk/res/ Android "xmlns:app=" Http://schemas.android.com/apk/res-auto "xmlns:tools=" Http://schemas.android.com/tools "Andro Id:layout_width= "Match_parent" android:layout_height= "match_parent" android:paddingbottom= "@dimen/activity_ Vertical_margin "android:paddingleft=" @dimen/activity_horizontal_margin "android:paddingright=" @dimen/activity_ Horizontal_margin "android:paddingtop=" @dimen/activity_vertical_margin "app:layout_behavior=" @string/appbar_ Scrolling_view_behavior "tools:showin=" @layout/activity_main "> <textview android:layout_width=" Match_pa Rent "android:layout_height=" match_parent "android:textsize=" 30DP "android:text=" @string/hejingzhoubl OG "android:id=" @+id/textview "/> <button android:layout_width=" Wrap_content "android:layout _height= "Wrap_content" android:text= "Testbutton"        Android:textallcaps= "false" android:id= "@+id/button" android:layout_aligntop= "@+id/textview" Android:layout_centerhorizontal= "true" android:layout_margintop= "197DP"/></relativelayout>


Second, Activityu_layout.xml
<?xml version= "1.0" encoding= "Utf-8"? ><android.support.design.widget.coordinatorlayout xmlns:android= " Http://schemas.android.com/apk/res/android "xmlns:tools=" Http://schemas.android.com/tools "android:layout_width= "Match_parent" android:layout_height= "match_parent" xmlns:app= "Http://schemas.android.com/apk/res-auto" android:f Itssystemwindows= "true" android:background= "#cc33cc" tools:context= " Com.example.hejingzhou.floatbutton.MainActivity "> <android.support.design.widget.appbarlayout android:layo Ut_width= "Match_parent" android:layout_height= "wrap_content" android:theme= "@style/apptheme" > <            Android.support.v7.widget.Toolbar android:id= "@+id/toolbar" android:layout_width= "Match_parent" android:layout_height= "? attr/actionbarsize" android:background= "#778899" Android:popuptheme= " @style/apptheme "/> </android.support.design.widget.AppBarLayout> <inClude layout= "@layout/content_layout"/> <android.support.design.widget.floatingactionbutton android:id= "@ +id/flotbutton "android:layout_width=" 50DP "android:layout_height=" 50DP "app:backgroundtint=" #ff87ffe        B "App:ripplecolor=" #708090 "android:layout_gravity=" Bottom|end "android:layout_margin=" 13DP " android:src= "@drawable/fly1"/></android.support.design.widget.coordinatorlayout>

Third, Menu.xmlmenu files need to be placed in the menu folder, the default directory does not have this folder, so to create new, folder directory hierarchy is:

<?xml version= "1.0" encoding= "Utf-8"? ><menu xmlns:android= "Http://schemas.android.com/apk/res/android" xmlns:app= "Http://schemas.android.com/apk/res-auto" ><!--1.alaways: This value causes the menu item to always appear on the Actionbar. 2.ifRoom: If there is enough space, this value will cause the menu to appear on the Actionbar. 3.never: This value menu will never appear in Actionbar yes. 4.withText: This value causes the menu to be displayed along with its icon and menu text. Android:orderincategory = The priority of each item in the Actionbar, the higher the value the lower the priority, the Actionbar place is not enough to be placed in the overflow--<item android:id= "@+id/edit" android:title= "edit" android:orderincategory = "android:icon=" @drawable/bian "app : showasaction= "Ifroom"/> <!--Find a problem is that although the ifroom has been set, it has entered the never menu--<item android:id= "@+ Id/find "android:title=" find "android:orderincategory =" android:icon= "@drawable/cha" App:sho wasaction= "Ifroom"/> <item android:id= "@+id/setmenu" android:orderincategory= "The Android:t" itle= "Personality Settings" app:showasaction= "Never"/> <item android:iD= "@+id/messagemenu" android:orderincategory= "android:title=" "My Message" app:showasaction= "Never"/> </menu>


Iv. Mainactivity.java
Package Com.example.hejingzhou.floatbutton;import Android.support.design.widget.floatingactionbutton;import Android.support.design.widget.snackbar;import Android.support.v7.app.appcompatactivity;import Android.os.Bundle; Import Android.support.v7.widget.toolbar;import Android.util.log;import Android.view.menu;import Android.view.menuitem;import Android.view.view;import Android.widget.button;import Android.widget.Toast;public    Class Mainactivity extends Appcompatactivity {private String TAG = GetClass (). Getsimplename ();        @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);        Setcontentview (R.layout.activity_main);        Button Buttontest = (button) Findviewbyid (R.id.button);                Buttontest.setonclicklistener (New View.onclicklistener () {@Override public void OnClick (View v) {            Toast.maketext (Mainactivity.this, "testactivity", Toast.length_short). Show ();        }        }); //The sidebar is not the title bar Toolbar Toolbar = (Toolbar) Findviewbyid (R.id.toolbar);        Toolbar.setnavigationicon (R.DRAWABLE.FLY1);        Toolbar.settitle ("main title");        Toolbar.setlogo (R.drawable.xiao);        Toolbar.setsubtitle ("subtitle");        LOG.I (TAG, "" + Toolbar.getcontentinsetleft ());        Setsupportactionbar (toolbar);  Toolbar.setnavigationonclicklistener (New View.onclicklistener () {@Override public void OnClick (View            V) {Toast.maketext (Mainactivity.this, "clicked Navigation bar Icon", Toast.length_short). Show ();        }        });        Floating button Floatingactionbutton Floatbutton = (Floatingactionbutton) Findviewbyid (R.id.flotbutton);                Floatbutton.setonclicklistener (New View.onclicklistener () {@Override public void OnClick (View v) { Snackbar.make (V, "You clicked Floatbutton", Snackbar.length_short). Setaction ("Action", nul            L). Show ();    }        });      }//Menu @Overridepublic boolean Oncreateoptionsmenu (Menu menu) {getmenuinflater (). Inflate (R.menu.menu, menu);    return true;        } @Override public boolean onoptionsitemselected (MenuItem item) {int id = item.getitemid ();        if (id = = R.id.setmenu) {toast.maketext (Mainactivity.this, "set menu selected", Toast.length_short). Show ();        }else if (id = = R.id.messagemenu) {toast.maketext (mainactivity.this, "Personal information selected", Toast.length_short). Show ();        }else if (id = = R.id.find) {toast.maketext (mainactivity.this, "select Find", Toast.length_short). Show ();        }else if (id = = R.id.edit) {toast.maketext (mainactivity.this, "edit Info", Toast.length_short). Show ();    } return super.onoptionsitemselected (item); } @Override public void Setsupportactionbar (Toolbar Toolbar) {Toolbar.setonclicklistener (new View.onclicklis Tener () {@Override public void OnClick (View v) {toast.maketext (mainactivity.this, "dotHit the toolbar Bar ", Toast.length_short). Show ();        }        });    Super.setsupportactionbar (toolbar); }}
</pre><pre code_snippet_id= "1626955" snippet_file_name= "blog_20160328_6_5301894" name= "code" class= "Java" >/** * Set Navigationicon icon Click Listen Method There are two types of * 1.setSupportActionBar (toolbar); * Toolbar.setnavigationonclicklistener (this); * Method 1 Note that it must be placed after the Setsupportactionbar method. * * *. In the Onoptionsitemselected method to determine the * if (id==android. R.id.home) {//toast.maketext (Mainactivity.this, "You Clicked Lock Icon", Toast.length_short). Show ();} */

Effect:

Source: http://download.csdn.net/detail/csdnhejingzhou/9474830



Android Studio Layout Template One of Floatbutton and toolbar

Related Article

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.