与自定义视图不与全宽度显示的扩展工具栏自定义、视图、宽度、不与

2023-09-06 02:39:03 作者:独醉

我经历了很多答案,这里涉及到工具栏,但没有一个答案可以帮助我。

I went through lots of answers here related to Toolbar but none of the answers could help me.

我试图做到的,是有一个扩展工具栏whhich会显示一个标志,该活动的可能是一个名称/应用程序,它有一个动作按钮/抽屉切换到右侧将显示一个导航类抽屉到右侧,与其他选项一样设置,也是一个导航标签在底部,将允许用户(在一个月内不同天)不同片段之间移动溢出菜单。

What I'm trying to achieve is to have an extended toolbar whhich will display a logo, possibly a name of the Activity/App, it will have an action button/drawer toggle to the right that will display a navigation-like drawer to the right, an overflow menu with other options like settings and also a navigation Tab at the bottom that will allow the user to move between different fragments (different days in a month).

的办法,我想实现,这是通过工具栏。 首先,我创建工具栏,并添加我的自定义视图。

The way I'm trying to achieve this is through toolbar. First I create the toolbar and add my custom view.

    <?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/toolbar_actionbar"
        android:layout_width="match_parent"
        android:layout_height="@dimen/min_double_toolbar_height"
        app:theme="@style/ThemeOverlay.AppCompat.ActionBar"
        android:minHeight="?attr/actionBarSize"
        android:background="@color/primary"

        app:contentInsetStart="0dp"
        app:contentInsetEnd="0dp"
        app:contentInsetLeft="0dp"
        app:contentInsetRight="0dp"
        android:clipToPadding="false"
        >
        <!-- ThemeOVerlay Makes sure the text and items are using solid colors-->

        <include
            android:layout_width="match_parent"
            android:layout_height="72dp"
            android:layout_gravity="bottom"
            layout="@layout/day_navigation_tab"
            />

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

day_navigation_tab仅仅是一个横向与72dp的填充(按指南)两个图像的意见,并与布局重文本视图设置为1,所以它绵延整个可用空间。 72dp的和的高度。

day_navigation_tab is just a horizontal with Two image views with Padding of 72dp (as by guidelines) and a text view with layout weight set to 1 so it stretches for the whole available space. And a height of 72dp.

现在在我的BaseActivity XML包括我的工具栏上的主背景下的的FrameLayout(否则工具栏将包括未知原因,我整个屏幕(我花了年龄figre说出来))

Now in my BaseActivity XML I include the toolbar in the Framelayout of the main context (otherwise the toolbar would cover the whole screen for an unknown reason for me (took me ages to figre that out))

<...ommited>

    <FrameLayout
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <include
            android:id="@+id/toolbar"
            layout="@layout/app_bar"
            />
    </FrameLayout>

    <!-- android:layout_gravity="start" tells DrawerLayout to treat
         this as a sliding drawer on the left side for left-to-right
         languages and on the right side for right-to-left languages.
         If you're not building against API 17 or higher, use
         android:layout_gravity="left" instead. -->
    <!-- The drawer is given a fixed width in dp and extends the full height of
         the container. -->
    <fragment android:id="@+id/navigation_drawer"
              android:layout_width="@dimen/navigation_drawer_width"
              android:layout_height="match_parent"
              android:layout_gravity="right"
              android:name="alterway.agency.timeentry.NavigationDrawerFragment"
              tools:layout="@layout/fragment_navigation_drawer"
              app:layout="@layout/fragment_navigation_drawer"
    />


</android.support.v4.widget.DrawerLayout>

然而,当我使用工具栏我吹的动作条中onCreateOptionsMenu我的自定义视图获取收缩,也不会延长创建选项边缘的菜单。 下方的图片说明了更好的,这是从设计视图中的Andr​​oid Studio中的截图。 黄色矩形表示,其中的选项也将被放置。 紫色指示在DesignView原始大小。黑色表示在运行应用程序时的大小。

However, when I use the toolbar I inflate the Menu on the actionBar in onCreateOptionsMenu my custom view gets shrinked and won't extend the edge of the created options. A picture below illustrates that better, It's a screenshot from a Design View in Android Studio. Yellow rectangle indicates where the option items will be placed. Purple indicates the original size in the DesignView. Black indicates the size when running the app.

感谢您的任何帮助。

相关问题,这可能是有用的人谁遇到这种寻求解决类似的问题:

Related questions that might be useful to anybody who comes across this looking to solve a similar problem:

design - 自定义视图没有使用全宽支持工具栏 How我设置在Android上升的扩展栏 design - Support Toolbars custom view not using full width How do I set up an extended toolbar on Android L

推荐答案

因此​​,为了实现这一目标,并完全控制我创建了两个工具栏工具栏上的填充。第一个工具栏的56dp和第二与72dp的高度,一起形成一个双层工具栏所指定的材料设计标准高度。

So in order to achieve this and have complete control over the padding in the toolbar I created two toolbars. The first toolbar with standard height of 56dp and second with height of 72dp which together made a double layered toolbar as specified by material design.

和,因为我没有任何膨胀菜单项的第二个工具栏里面的行为我所有的cusotm意见所需。

And because I am not inflating any menu items in the second toolbar all my cusotm views inside behave as desired.

这些线路仍然需要使用,虽然

These lines still need to be used though

    app:contentInsetStart="0dp"
    app:contentInsetEnd="0dp"
    app:contentInsetLeft="0dp"
    app:contentInsetRight="0dp"
    android:clipToPadding="false"

这解决了我的问题,所以我现在包括两个工具栏到我的XML。

This solved my issue so now I'm including two toolbars into my XMl.