Alexander Farber
Alexander Farber

Reputation: 22988

Providing Up (aka Back) Navigation - with UI Fragments

The Google doc Providing Up Navigation explains, how to display an Up button in an application with several Activities (by specifying "parent" Activities in AndroidManifest.xml):

screenshot

However I am working on a Bluetooth application (starting with minSdkVersion=18) which has a single MainActivity and 3 Fragments:

So I have changed the base class to ActionBarActivity:

public class MainActivity extends ActionBarActivity 
                          implements BleWrapperUiCallbacks {

And I call the setDisplayHomeAsUpEnabled(true) method:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);  
    setContentView(R.layout.activity_root);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

This displays the Up button in my app, however I still have 3 questions:

  1. How to hide the Up button (when I am showing the MainFragment)?
  2. How to "wire" the Up button - currently touching it does nothing?
  3. What to use instead of the following line in my AndroidManifest.xml?

android:theme="@android:style/Theme.Holo.NoActionBar"

Upvotes: 2

Views: 104

Answers (1)

Omar
Omar

Reputation: 458

I can answer the second question for providing the up navigation by override this method :

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

Upvotes: 2

Related Questions