Android 工具栏背景
Android toolbar background
如何在工具栏上添加位于抽屉和后退箭头图标后面的 imageview?该图像视图应与工具栏高度匹配,并且左侧没有任何边距或填充。我已经尝试了一段时间来实现这一点,而且我想出的唯一解决方案是制作自定义工具栏
示例:
Toolbar example
你可以试试这个:
<RelativeLayout
android:id="@+id/my_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:theme="@style/ActionBarThemeOverlay"
app:popupTheme="@style/ActionBarPopupThemeOverlay"
android:elevation="4dp"
android:background="@color/white">
<ImageView
android:layout_width="60dp"
android:layout_height="?attr/actionBarSize"
android:src="@drawable/yourImage"/>
</RelativeLayout>
在布局中创建 appbar_layout_xml 添加以下代码
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/my_img"
app:titleTextColor="@color/colorWhite"
android:theme="@style/ThemeOverlay.AppCompat.Light"
>
</android.support.v7.widget.Toolbar>
并在您的 activity_xml 中包含 appbar_layout_xml 布局
在样式中保持主题为 NoActionBar
如何在工具栏上添加位于抽屉和后退箭头图标后面的 imageview?该图像视图应与工具栏高度匹配,并且左侧没有任何边距或填充。我已经尝试了一段时间来实现这一点,而且我想出的唯一解决方案是制作自定义工具栏
示例:
Toolbar example
你可以试试这个:
<RelativeLayout
android:id="@+id/my_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:theme="@style/ActionBarThemeOverlay"
app:popupTheme="@style/ActionBarPopupThemeOverlay"
android:elevation="4dp"
android:background="@color/white">
<ImageView
android:layout_width="60dp"
android:layout_height="?attr/actionBarSize"
android:src="@drawable/yourImage"/>
</RelativeLayout>
在布局中创建 appbar_layout_xml 添加以下代码
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/my_img"
app:titleTextColor="@color/colorWhite"
android:theme="@style/ThemeOverlay.AppCompat.Light"
>
</android.support.v7.widget.Toolbar>
并在您的 activity_xml 中包含 appbar_layout_xml 布局 在样式中保持主题为 NoActionBar