Open top menu


In this blog explain How to display and set back arrow button on ActionBar in android. Explain Below....

Basically, we are used this button because Onclick back arrow Button redirect Back Activity in android .

                /* 
* display Home Back Button on actionbar  
*/
getActionBar().setDisplayHomeAsUpEnabled(true);
/* 
* display Home Back Button Enable  
*/
getActionBar().setHomeButtonEnabled(true);








MainActivity.java
...................................................................................................................................................................

@SuppressLint("ResourceAsColor")
public class MainActivity extends Activity {

 

@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getActionBar().setTitle("ActionBar");

/* 
* display Home Back Button on actionbar  
*/
getActionBar().setDisplayHomeAsUpEnabled(true);
/* 
* display Home Back Button Enable  
*/
getActionBar().setHomeButtonEnabled(true);

setContentView(R.layout.activity_main);
 


/* 
* Redirect method 
*/
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {

case android.R.id.home:
finish();
break;

default:
break;
}
 
return super.onOptionsItemSelected(item);
}

}
...................................................................................................................................................................

0 comments