What should be added to the manifest. The getSupportActionBar () method works?

Into the Android developer tutorials they explained, when I click the icon on the left it gives me a "home page" with the below code

ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);

      

and I knew what I needed to add for the ActionBarActivity class. but still i cant go back to the main page maybe a problem with the manifest.

Display.java

@Override 
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.grid_main);
    GridView gridview = (GridView) findViewById(R.id.gridview);
    gridview.setAdapter(new ImageAdapter(this));
    android.support.v7.app.ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);

      

This is the manifest:

<activity
        android:name="com.example.sqlfirst.Display"
        android:label="@string/app_name"
         android:parentActivityName="com.example.sqlfirst.Display.MainActivity" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.example.sqlfirst.Display.MainActivity" />
        </activity>

      

why doesn't it go to the home page? Please note, my main page: MainActivity.java

+3


source to share


1 answer


From the link http://developer.android.com/training/implementing-navigation/ancestral.html#up

setDisplayHomeAsUpEnabled(true);

      

adds the left side of the caret next to the app icon and includes it as an action button so that when the user clicks on it, your activity gets a call to onOptionsItemSelected (). The identifier for the action is android.R.id.home.

You have to override onOptionsItemSelected and use NavUtils



public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
// Respond to the action bar Up/Home button
case android.R.id.home:
    NavUtils.navigateUpFromSameTask(this);
    return true;
}
return super.onOptionsItemSelected(item);

      

}

More details at http://developer.android.com/training/implementing-navigation/ancestral.html#NavigateUp

+2


source







All Articles