android - How can I program the back button on the action bar to go back to the previous activity? -
i want know how can program button in action bar revert previous activity , finish activity shown?
about.class
public class extends fragmentactivity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.about); getactionbar().setdisplayhomeasupenabled(true); // tracker. tracker t = ((analyticstracker) getapplication()).gettracker(analyticstracker.trackername.app_tracker); // enable display features can see demographics in google analytics t.enableadvertisingidcollection(true); // set screen name. t.setscreenname("about"); // send screen view. t.send(new hitbuilders.appviewbuilder().build()); fragmentmanager fragmentmanager = getfragmentmanager(); android.app.fragmenttransaction fragmenttransaction = fragmentmanager.begintransaction(); adview ls_fragment = new adview(); fragmenttransaction.replace(android.r.id.content, ls_fragment); adview madview = (adview) findviewbyid(r.id.adview); adrequest adrequest = new adrequest.builder().build(); madview.loadad(adrequest); } }
the layout page. about.xml
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:ads="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id = "@+id/content_frame" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/black" > <relativelayout android:background="@mipmap/home" android:layout_width="match_parent" android:layout_height="match_parent"> <imageview android:layout_width="200dp" android:layout_height="200dp" android:id="@+id/imageview" android:background="@mipmap/ic_launcher" android:layout_alignparenttop="true" android:layout_centerhorizontal="true" /> <textview android:layout_width="300dp" android:layout_height="250dp" android:id="@+id/textview9" android:gravity="center" android:textsize="16dp" android:text="@string/abouttext" android:background="@drawable/text" android:layout_below="@+id/imageview" android:layout_centerhorizontal="true" /> <fragment android:layout_width="match_parent" android:layout_height="50dp" android:name="course.labs.converjz.adview" android:id="@+id/fragment" tools:layout="@layout/adview" android:layout_gravity="center|bottom" android:layout_alignwithparentifmissing="false" android:layout_alignparentbottom="true" android:layout_alignparentstart="true" /> </relativelayout> </relativelayout>
the specific style creates actionbar , adds button it. styles.xml
<style name= "menubar" parent="@style/appbasetheme"> <item name = "android:homeasupindicator">@mipmap/back</item> </style>
the button image in mipmap icon folder.
just change getactionbar
getsupportactionbar
shown:
getsupportactionbar().setdisplayhomeasupenabled(true);
Comments
Post a Comment