Reputation: 69
I am using a custom toolbar in my app. Toolbar adds extra space at its left side. This is my Xml file:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:id="@+id/customActionBar"
android:layout_height="wrap_content"
android:background="@color/titleBar">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<ImageButton
android:layout_width="0dp"
android:layout_height="match_parent"
android:id="@+id/leftIcon"
android:src="@drawable/abc_btn_rating_star_on_mtrl_alpha"
android:background="@android:color/transparent"
android:layout_weight="0.2"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/actionTitleText"
android:text="@string/app_name"
android:textColor="@color/abc_primary_text_disable_only_material_dark"
android:textSize="@dimen/text_22sp"
android:padding="@dimen/size_12dip"
android:gravity="center_horizontal"
android:layout_weight="0.6"/>
<ImageButton
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/rightIcon"
android:src="@drawable/abc_btn_rating_star_on_mtrl_alpha"
android:background="@android:color/transparent"
android:layout_weight="0.2"/>
</LinearLayout>
</android.support.v7.widget.Toolbar>
Can you please help? it gives some margin from left of screen, but i have not given any margin attribute. This is code to inflate that into activity:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.setContentView(R.layout.activity_main);
baseViewContent = (LinearLayout) findViewById(R.id.main_activity_content_view);
viewController = new ViewController(this, baseViewContent);
activity = this;
// Set a toolbar to replace the action bar.
android.support.v7.widget.Toolbar toolbar = (android.support.v7.widget.Toolbar) findViewById(R.id.customActionBar);
setSupportActionBar(toolbar);
Upvotes: 2
Views: 1974
Reputation: 61
For other people like me: It was the title in the toolbar that I was not seeing because it had the same color as background. You can remove it if you want with getSupportActionBar().setDisplayShowTitleEnabled(false)
Upvotes: 0
Reputation: 474
Use
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
to remove the extra space.
Ref: https://stackoverflow.com/a/27309500
Upvotes: 12