支持工具栏的自定义视图不使用全宽 [英] Support Toolbar's custom view not using full width

查看:194
本文介绍了支持工具栏的自定义视图不使用全宽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用支持v7的工具栏。我添加了一个自定义视图,但自定义视图似乎不符合match_parent。它只会伸展到它看到的第一个图标。有人知道这个修复吗?还是工具栏不是要这样用?





我的代码:

 < FrameLayout xmlns:android =http:// schemas .android.com / apk / res / android
xmlns:tools =http://schemas.android.com/tools
xmlns:app =http://schemas.android.com / apk / res-auto
android:layout_width =match_parent
android:layout_height =match_parent
android:clipChildren =false
tools:context =com .example.activities.ToolbarActivity
>

< android.support.v7.widget.Toolbar
android:id =@ + id / toolbar
android:layout_height =100dp
android :layout_width =match_parent
android:minHeight =?attr / actionBarSize
android:background =@ color / light_gray
app:popupTheme =@ style / ThemeOverlay.AppCompat。
app:theme =@ style / ThemeOverlay.AppCompat.Dark.ActionBar
android:gravity =bottom
android:clipChildren =false
>

< RelativeLayout
android:layout_width =match_parent
android:layout_height =30dp
android:background =@ color / green
>


< / RelativeLayout>

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

< / FrameLayout>


解决方案

我在Simon的链接中取得了成功: / p>

 < RelativeLayout xmlns:android =http://schemas.android.com/apk/res/android
xmlns:tools =http://schemas.android.com/tools
xmlns:app =http://schemas.android.com/apk/res-auto
android:layout_width =match_parent
android:layout_height =match_parent
android:clipChildren =false
工具:context =com.example.activities.ToolbarActivity>

< android.support.v7.widget.Toolbar
android:id =@ + id / toolbar
android:layout_height =100dp
android :layout_width =match_parent
android:minHeight =?attr / actionBarSize
android:background =@ color / light_gray
app:popupTheme =@ style / ThemeOverlay.AppCompat。光
app:theme =@ style / ThemeOverlay.AppCompat.Dark.ActionBar/>

< RelativeLayout
android:layout_width =match_parent
android:layout_height =30dp
android:layout_marginTop =70dp
android:背景= @色/绿色 >

< / RelativeLayout>

< / RelativeLayout>


I'm using support v7's toolbar. I added a custom view, but the custom view doesn't seem to obey "match_parent". It would only stretch as far as the first icon it sees. Does anyone know a fix to this? Or is the toolbar not meant to be used this way?

My code:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clipChildren="false"
    tools:context="com.example.activities.ToolbarActivity"
    >

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_height="100dp"
        android:layout_width="match_parent"
        android:minHeight="?attr/actionBarSize"
        android:background="@color/light_gray"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        android:gravity="bottom"
        android:clipChildren="false"
        >

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="30dp"
            android:background="@color/green"
            >


        </RelativeLayout>

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

</FrameLayout>

解决方案

I have succeed with the approach in Simon's link:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clipChildren="false"
    tools:context="com.example.activities.ToolbarActivity">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_height="100dp"
        android:layout_width="match_parent"
        android:minHeight="?attr/actionBarSize"
        android:background="@color/light_gray"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:layout_marginTop="70dp"
        android:background="@color/green">

    </RelativeLayout>

</RelativeLayout>

这篇关于支持工具栏的自定义视图不使用全宽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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