2016-11-07 55 views
0

我试图做这样的事情:在工具栏的背景添加图片中的Android

我的工具栏的当前代码:

<android.support.v7.widget.Toolbar 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/toolbar" 
    android:layout_height="wrap_content" 
    android:layout_width="match_parent" 
    android:fitsSystemWindows="true" 
    android:minHeight="?attr/actionBarSize" 
    app:theme="@style/MyTheme.ActionBarStyle" 
    android:background="@android:color/transparent"> 

    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_marginLeft="-10dp" 
     android:gravity="center"> 
     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/explore_morning" 
      android:contentDescription="@string/app_name" /> 
    </RelativeLayout> 

</android.support.v7.widget.Toolbar> 

我的图像不覆盖整个屏幕

回答

1

而不是添加新的图像视图,设置工具栏背景已解决我的问题。

<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/toolbar" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@drawable/explore_morning" 
    android:fitsSystemWindows="true" 
    android:minHeight="64dp" 
    app:theme="@style/MyTheme.ActionBarStyle"> 


</android.support.v7.widget.Toolbar>