Toolbar

我们现在一般都用Toolbar 不在用Actionbar了。这是因为Actionbar在定制时,会出现在不同的手机上适配有问题。在加上在goole 退出的Meteral Design的设计风格,而Toolbar就可以实现,并且actionbar的很多功能在Toolbar上都可以实现。

在写toolbar时一定要在启动的的activity的里面设置style方式,不然会与系统发生冲突。

以下是Toolbar的代码

在toolbar中你可以自定义样式

<?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"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:background="?attr/colorPrimary"
    android:minHeight="?attr/actionBarSize"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    app:theme="@style/ThemeOverlay.AppCompat.ActionBar">

    <TextView  android:layout_height="wrap_content"
               android:layout_width="wrap_content"
               android:layout_gravity="right"
               android:textSize="20dp"
               android:text="@string/title_left"
               android:id="@id/more_text"
              android:layout_marginRight="20dp"/>
    <TextView android:layout_height="wrap_content"
              android:layout_width="wrap_content"
              android:layout_gravity="left"
              android:textSize="20dp"
              android:id="@id/me_text"
              android:layout_marginLeft="20dp"
              android:text="@string/title_right"/>
</android.support.v7.widget.Toolbar>


这是style代码

<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">


        <!-- toolbar(actionbar)颜色 -->
        <item name="colorPrimary">#8B4500</item>
        <!-- 状态栏颜色 -->
        <item name="colorPrimaryDark">#8B5A00</item>
        <!-- 窗口的背景颜色 -->
        <item name="android:windowBackground">@android:color/white</item>
        <!-- SearchView -->
        <item name="searchViewStyle">@style/MySearchViewStyle</item>
    </style>
    <style name="MySearchViewStyle" parent="Widget.AppCompat.SearchView"/>
    <style name="AppTheme" parent="@style/AppBaseTheme"></style>

配置文件中的Application中进行引用

最后在activity中进行设置Toolbar的内容即可。


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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值