Reputation: 22018
I'm using a custom layout on my ABS ActionBar
, like
View abview = getLayoutInflater().inflate(R.layout.custombar, null);
getSupportActionBar().setCustomView(abview);
Now there's no home/ up button, I already tried:
getSupportActionBar().setHomeButtonEnabled(true);
When using a custom view on my ActionBar
, do I have to take care of the up button all myself?
Upvotes: 1
Views: 2881
Reputation: 1792
I had the same problem, and it appears to be dependent on what order you specify things. Here is how I get my custom view to show up, while still preserving the home/back action (this code is in onCreateOptionsMenu
):
ActionBar actionBar = getSupportActionBar();
// 1) Inflate your menu, if you have also need actions
getSupportMenuInflater().inflate(R.menu.normal_action_menu, menu);
// 2) Set your display to custom next
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
// 3) Do any other config to the action bar
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowTitleEnabled(false);
// 4) Now set your custom view
actionBar.setCustomView(R.layout.custom_view);
Upvotes: 5
Reputation: 412
You can add a custom action view in your action bar, like this :
@Override
public boolean onCreateOptionsMenu(Menu menu) {
if (DEBUG_MODE) {
Log.d(TAG, "onCreateOptionsMenu()");
}
getSupportMenuInflater().inflate(R.menu.menu_generic, menu);
// Progress
final MenuItem progress = menu.findItem(R.id.menu_progress);
progress.setActionView(R.layout.action_view_progress);
mProgressText = (TextView) progress.getActionView().findViewById(R.id.total_achievement_text);
return super.onCreateOptionsMenu(menu);
}
menu_genric.xml:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/menu_progress"
android:showAsAction="always"/>
</menu>
After, you can increase your number with reference of mProgressText
Upvotes: 1
Reputation: 412
If you use a custom View in ActionBar (ActionBarsherlock) you must manage itself all actionBar. So It's better to keep ActionBar and set xml to background and/or set customview in specific element. What do you want to do in your custom actionbar ?
Upvotes: 2