Toolbar使用和踩过得一些属性不能设置的坑

Toolbar 是在 Android 5.0推出的一个非常方便使用的一个导航控件。今天我们来学习使用一下。首先我们查看一下TooBar的源码。
这里写图片描述
可以知道TooBar继承自ViewGroup我们可以往里面添加我们自己的布局


    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        toolbar:navigationIcon="@mipmap/ic_drawer_home"
        toolbar:theme="@style/AppThemeMyToobar"
        toolbar:logo="@mipmap/ic_launcher"
        toolbar:titleTextColor="@color/white"
        toolbar:title="标题"
        toolbar:subtitleTextColor="@color/white"
        toolbar:subtitle="啦啦啦"
        >

        <!--自定义控件-->
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Hello world"/>
    </android.support.v7.widget.Toolbar>

运行情况如图所示
这里写图片描述

这里有个坑我们要注意。Toolbar属性设置无效

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/color_0176da"
        android:logo="@mipmap/ic_launcher"
        android:navigationIcon="@mipmap/ic_drawer_home"
        android:subtitle="456"
        android:title="123">

        <!--自定义控件-->
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Hello world" />
    </android.support.v7.widget.Toolbar>
</LinearLayout>

这里写图片描述
设置的 logo、navigationIcon、subtitle、title 都没有!只要把没有用的设置全部改成自己定义的命名空间。
这里写图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值