Reputation: 614
I am creating a customized home icon. The codes for the customization is as follows,
View customView = getLayoutInflater().inflate(R.layout.action_bar_display_options_custom, null);
customView.findViewById(R.id.action_home).setOnClickListener(
new OnClickListener() {
@Override
public void onClick(View v) {
toggle();
}
});
actionBar.setCustomView(customView, new ActionBar.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
actionBar.setDisplayShowCustomEnabled(true);
This is action_bar_display_options_custom.xml
,
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<ImageView
android:id="@+id/action_home"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/btn_home" />
<TextView
android:id="@+id/action_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content" /> </LinearLayout>
This's the screenshot,
This is home's icon (that space isn't a part of the image view),
So, how can I remove the space in front of the view?
Upvotes: 3
Views: 1503
Reputation: 2055
I solved this issue by adding following lines to my code
getSupportActionBar().setDisplayShowHomeEnabled(false);
getSupportActionBar().setCustomView(view); // set custom view here
getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar().setDisplayOptions(0, ActionBar.DISPLAY_SHOW_CUSTOM);
getSupportActionBar().setDisplayShowCustomEnabled(true);
Hope this helps you.
Upvotes: 3
Reputation: 2106
Remove the padding or margin that you have set in the parent layout, that will solve the problem. Please feel free to ask doubts, also do let me know if that solves your problem.
Upvotes: 0