2

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:

  • MainFragment.java
  • SettingsFragment.java
  • ScanningFragment.java

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"

Alexander Farber
  • 21,519
  • 75
  • 241
  • 416

1 Answers1

2

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);
}
Omar
  • 458
  • 2
  • 10