Android back option in action bar -
when created activity automatically added main activity alternative in action bar. looks functions it:
@override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.app_settings, menu); homecoming true; } @override public boolean onoptionsitemselected(menuitem item) { // handle action bar item clicks here. action bar // automatically handle clicks on home/up button, long // specify parent activity in androidmanifest.xml. int id = item.getitemid(); if (id == r.id.action_settings) { homecoming true; } homecoming super.onoptionsitemselected(item); }
is there way create go using finish()? right looks resets values saved , want maintain them. when tried working finish() didn't i'm not sure how utilize in action bar.
this simpler , works perfect:
public class backbuttonexample extends activity { @suppresslint("newapi") protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.duahs); actionbar bar = getactionbar(); bar.setbackgrounddrawable(new colordrawable(color.parsecolor("#0b4c5f"))); bar.setdisplayhomeasupenabled(true); } @override public boolean onoptionsitemselected(menuitem item) { switch (item.getitemid()) { case android.r.id.home: this.finish(); homecoming true; default: homecoming super.onoptionsitemselected(item); } } }
android
No comments:
Post a Comment