Reputation: 3214
My code for showing custom ActionBar is given below. I am using the slidingmenu library from https://github.com/jfeinstein10/SlidingMenu
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
View customActionBar = getLayoutInflater().inflate(R.layout.layout_actionbar,
new LinearLayout(this), false);
getActionBar().setCustomView(customActionBar);
setBehindContentView(R.layout.activity_menu);
slidingMenu=getSlidingMenu();
slidingMenu.setMode(SlidingMenu.RIGHT);
slidingMenu.setBehindOffset(100);
TextView tv=(TextView) findViewById(R.id.textView1);
tv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
slidingMenu.showMenu();
}
});
}
Markup for the custom ActionBar:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="?android:attr/dividerVertical"
android:dividerPadding="12dp"
android:showDividers="middle">
<LinearLayout android:id="@+id/action_cancel"
style="@style/CustomActionButton">
<ImageView android:src="@drawable/ic_menu_cancel_holo_light" style="@style/ActionButtonImage" />
<TextView android:text="DISCARD" style="@style/ActionButtonText" />
</LinearLayout>
<LinearLayout android:id="@+id/action_done" style="@style/CustomActionButton">
<ImageView android:src="@drawable/ic_menu_done_holo_light" style="@style/ActionButtonImage" />
<TextView android:text="DONE" style="@style/ActionButtonText" />
</LinearLayout>
</LinearLayout>
When I run this application, the default dark ActionBar is showing not the custom one. How to fix this ?
Upvotes: 0
Views: 253
Reputation: 3564
Try doing it his way:
/*Inflate your custom actionBar layout*/
final ViewGroup customActionBar = (ViewGroup) getLayoutInflater().inflate(R.layout.layout_actionbar, null);
/*Get actionbar*/
ActionBar actionBar = getActionBar();
/*set custom view*/
actionBar.setDisplayShowCustomEnabled(true);
/*Define custom view*/
actionBar.setCustomView(customActionBar );
Upvotes: 1
Reputation: 1046
Try this before setting custom content of action bar
ab.setDisplayShowCustomEnabled(true);
Upvotes: 0
Reputation: 689
If you want to use Sherlock Sliding menu, then you have to use Sherlock actionbar.
If you dont want sherlock then check this, http://www.androidhive.info/2013/11/android-sliding-menu-using-navigation-drawer/
Upvotes: 0