android工具栏:如何使工具栏的背景图像位于顶部,菜单项位于顶部 [英] android toolbar: how to have a toolbar with image in the background and menu items on top

查看:86
本文介绍了android工具栏:如何使工具栏的背景图像位于顶部,菜单项位于顶部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用材质设计如何创建带有背景图像的工具栏.

Using material design how to create a toolbar with background image.

以下是我想要的:

我正在尝试以下代码:

<?xml version="1.0" encoding="utf-8"?>
<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/actionBar"
    android:layout_width="match_parent"
    android:layout_height="200dp"
    app:contentInsetEnd="0dp"
    app:contentInsetStart="0dp" 
    android:minHeight="200dp">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageViewplaces"
        android:src="@drawable/puri" 
        android:layout_gravity="center"/>

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

我得到的是:

推荐答案

如果您坚持使用ImageView而不是使用.setBackground(...)函数.

If you insist on using an ImageView over using the .setBackground(...) function.

您可以尝试将RelativeLayoutToolbar叠加在ImageView上,如下所示:

You can try using a RelativeLayout with the Toolbar overlaying an ImageView like this:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <ImageView
        android:id="@+id/imageViewplaces"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:adjustViewBounds="true"
        android:src="@drawable/YOUR_IMAGE" />

    <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/toolbar_actionbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        >

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


</RelativeLayout>

这篇关于android工具栏:如何使工具栏的背景图像位于顶部,菜单项位于顶部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆