Search code examples
androidandroid-actionbartitlebar

Android title bar custom view does not stretch


I use api 21 titlebar in my app. I want to stretch my button or Linearlayout on it, but I can't. my code:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.toolbartest.MainActivity" >
<android.support.v7.widget.Toolbar  
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/my_awesome_toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="#ff9900"> 
<Button
    android:layout_height="match_parent"
android:layout_width="match_parent"
android:text="GSSGSDGSDG"/>
</android.support.v7.widget.Toolbar>

</LinearLayout>![enter image description here][1]


Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayShowTitleEnabled(false);

I got this:

enter image description here


Solution

  • I solved it, here xml code:

    <android.support.v7.widget.Toolbar
        xmlns:plugshare="http://schemas.android.com/apk/res-auto"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/my_awesome_toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#ff9900"
        android:minHeight="?attr/actionBarSize"
        app1:contentInsetStart="0dp" >
    
     <Button
       android:layout_width="match_parent"
       android:layout_height="?attr/actionBarSize"
       android:text="GGSSSDFSDFSFFSDF" /> 
    </android.support.v7.widget.Toolbar>