Reputation: 14435
I need to add an ActionBar to my application but it has to be customized. From left to right: custom backbutton, custom dropdown list, custom button, Image in the middle, and two custom buttons on the right.
What is my best approach here? Is it possible using the ActionBar or will I be better off creating this as a Layout?
The minSdk is 14
Upvotes: 3
Views: 2150
Reputation: 597
You can use a SplitActionBar. Your application suppost to be running on Android 4.0 (API level 14) or higher
the fix is to always have an item in the top bar that prevents the bottom content from ever fitting in there, thus forcing everything into the bottom bar. Look at this sample project from another user:
<?xml version="1.0" encoding="utf-8"?
<manifest package="com.commonsware.android.actionbarbc"
xmlns:android="http://schemas.android.com/apk/res/android">
<application android:hardwareAccelerated="true"
android:icon="@drawable/cw"
android:label="@string/app_name">
<activity android:label="@string/app_name"
android:name=".InflationDemo"
android:uiOptions="splitActionBarWhenNarrow">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="4"
android:targetSdkVersion="11" />
<supports-screens android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:xlargeScreens="true" />
</manifest>
He used this code for his activity:
private void setupActionBar() {
ActionBar actionBar = getActionBar();
ViewGroup v = (ViewGroup)LayoutInflater.from(this)
.inflate(R.layout.conversation_list_actionbar, null);
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM,
ActionBar.DISPLAY_SHOW_CUSTOM);
actionBar.setCustomView(v,
new ActionBar.LayoutParams(ActionBar.LayoutParams.WRAP_CONTENT,
ActionBar.LayoutParams.WRAP_CONTENT,
Gravity.CENTER_VERTICAL | Gravity.RIGHT));
mUnreadConvCount = (TextView)v.findViewById(R.id.unread_conv_count);
}
http://developer.android.com/guide/topics/ui/actionbar.html#SplitBar
Upvotes: 2
Reputation: 337
I think it's better to use ActionBar. Custom dropdown list can be set by
private class MyAdapter extends BaseAdapter {
/**
* View displayed inside the Action Bar
*/
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View resultView = convertView;
if (resultView == null) {
resultView = mLayoutInflater.inflate(R.layout.spinner_main, null);
}
return resultView;
}
/**
* View Displayed inside list of possible options
*/
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
View resultView = convertView;
if (resultView == null) {
resultView = mLayoutInflater.inflate(R.layout.spinner_drop_down, null);
}
return resultView;
}
}
and then
getActionBar().setListNavigationCallbacks(new MyAdapter(), listener);
The other things, like custom back icon, you can achieve making styles for your ActionBar.
Upvotes: 3