Reputation: 926
I am currently using getActionBar().setHomeButtonEnabled(true);
it works fine but it requires api level 14 and without it I would be able to get all the way down to api 8 which would be awesome! If someone knows a way around this please let me know.
Upvotes: 1
Views: 110
Reputation:
You have to use support library and code will something look like this:
import android.support.v7.app.ActionBar
public class YourActivity extends ActionBarActivity {
ActionBar actionBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
actionBar = getSupportActionBar(); // now do whatever you want to do with this action bar
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// code for your action when you click home icon on action bar
break;
default:
break;
}
return true;
}
}
Upvotes: 2
Reputation: 17140
Use the v7 appcompat support library to get api 8 support for this method.
Instructions are located :
http://developer.android.com/tools/support-library/features.html#v7-appcompat Actionbar http://developer.android.com/tools/support-library/setup.html#libs-with-res
Upvotes: 1
Reputation: 2897
You can use the ActionBar
support library: http://developer.android.com/guide/topics/ui/actionbar.html
Instead of getActionBar()
, use getSupportActionBar()
Also, make sure this is your ActionBar
import:
import android.support.v7.app.ActionBar
Upvotes: 1
Reputation: 36289
Just use ActionBarSherlock or ActionBarCompat. These will both handle low API levels and use the native ActionBar for higher APIs automatically.
Upvotes: 1