Mainactivity.java
PackageCom.cela.one.cela1;importAndroid.os.bundle;importAndroid.support.design.widget.floatingactionbutton;importAndroid.support.design.widget.snackbar;importAndroid.support.v7.app.appcompatactivity;importAndroid.support.v7.widget.toolbar;importAndroid.view.view;importAndroid.view.menu;importAndroid.view.menuitem;public class Mainactivity extendsappcompatactivity {@Override protected voidOnCreate (Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate); Setcontentview (R.layout.activity_main); Toolbar Toolbar =(Toolbar) Findviewbyid (R.id.toolbar); Setsupportactionbar (toolbar); Floatingactionbutton fab =(Floatingactionbutton) Findviewbyid (R.id.fab); Fab.setonclicklistener (NewView.onclicklistener () {@Override public void OnClick (view view) {Snackbar.make (view, "Replace with your own AC tion ", Snackbar.length_long). Setaction (" Action ", null). Show ();}); } @Override public boolean oncreateoptionsmenu (Menu menu) {//Inflate the menu, this adds items to the action Bar if It is present. getmenuinflater (). Inflate (R.menu.menu_main, menu); return true;} @Override public Boolean Onoptionsitemselected (MenuItem Item) {//Handle Action Bar item clicks here. The action bar would//automatically handle clicks on the Home/up button, so long/As you specify a parent activity in a ndroidmanifest.xml. int id = Item.getitemid ();//noinspection simplifiableifstatement if (id = = r.id.action_ Settings) {return true;} return Super. onoptionsitemselected (item);}}
Activity_main.xml
<?xml version= "1.0" encoding= "Utf-8"? ><android.support.design.widget.coordinatorlayout 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 "android:layout_width=" match_parent "android:layout_height=" Match_parent "Androi D:fitssystemwindows= "true" tools:context= "com.cela.one.cela1.MainActivity" > < Android.support.design.widget.AppBarLayout android:layout_width= "match_parent" android:layout_height= "Wrap_c Ontent "Android:theme=" @style/apptheme.appbaroverlay "> <android.support.v7.widget.toolbar A Ndroid:id= "@+id/toolbar" android:layout_width= "match_parent" android:layout_height= "? Attr/actionBarS Ize "android:background="? Attr/colorprimary "App:popuptheme=" @style/apptheme.popupoverlay "/> </android.support.design.widget.AppBarLayout> <include layout= "@layout/content_main "/> <android.support.design.widget.floatingactionbutton android:id=" @+id/fab " Android:layout_width= "Wrap_content" android:layout_height= "wrap_content" android:layout_gravity= "Bottom|end" android:layout_margin= "@dimen/fab_margin" android:src= "@android:d rawable/ic_dialog_email"/></android .support.design.widget.coordinatorlayout>
Content_main.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 " android: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:context=" Com.cela.one.cela1.MainActivity " tools:showin=" @layout/activity_main "> <textview android: Layout_width= "Wrap_content" android:layout_height= "wrap_content" android:text= "Hello world!"/>< /relativelayout>
Menu_main.xml
Menu_main.xmlColor.xml
ColorDimens.xml
DimensString.xml
stringStyles.xml
Styles
———————————————————————————— Hand Split Line ——————————————————————————————————
The code in this article is all copied from the new project in Android Studio.
As a porter, there is no ownership of the code in this article.
So, for reference only.
"Porter" Android Studio New Project code [1]basic Activity with Floatingbutton, Menu