How do I remove the space in front of a custom view?
I am creating a custom house icon. The setting codes are 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 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 is a screenshot,
This is the house icon (this space is not part of the image),
So how can I remove the space in front of the view?
+3
source to share
2 answers
I solved this problem by adding the 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.
+3
source to share