Drawerlayout和ToolBar进行整合

news/2024/7/7 4:50:37

首先可以看一下效果

\

上一篇文章我们使用的是Drawerlayout和Naviagtion实现了侧滑的效果,大家可以看下http://blog.csdn.net/qq_24675479/article/details/78743924。这个项目是基于上个项目来实现的

第一步:我们定义一下样式,因为我们默认的Toolbar标题和图标是黑色的

<style name="AppTheme.ToolBar" parent="AppTheme">
    <!--  箭头  -->
    <item name="drawerArrowStyle">@style/AppTheme.DrawerArrowToggle</item>
    <item name="android:windowActionBarOverlay">@style/ActionButton.Overflow</item>
    <item name="actionOverflowButtonStyle">@style/ActionButton.Overflow</item>
    <item name="titleTextColor">@android:color/white</item>
</style>
<style name="ActionButton.Overflow" parent="android:style/Widget.Holo.Light.ActionButton.Overflow">
    <item name="android:src">@mipmap/ic_menu_more_overflow</item>
</style>
<style name="AppTheme.DrawerArrowToggle" parent="Base.Widget.AppCompat.DrawerArrowToggle">
    <item name="color">@android:color/white</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar"/>
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light"/>
第二步:将内容控件的布局修改一下:

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <android.support.v7.widget.Toolbar
        android:id="@+id/tool_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:minHeight="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:title="@string/app_name"
        android:theme="@style/AppTheme.ToolBar">

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

</LinearLayout>
第三步:定义一个toolbar_menu布局:

<item
    android:id="@+id/action_search"
    android:icon="@mipmap/ic_search"
    android:title="@string/menu_search"
    app:showAsAction="ifRoom" />
showAsAction的属性值有:

1)alaways:这个值会使菜单项一直显示在ActionBar上。

2)ifRoom:如果有足够的空间,这个值会使菜单显示在ActionBar上。

3)never:这个值菜单永远不会出现在ActionBar是。

4)withText:这个值使菜单和它的图标,菜单文本一起显示。

第四步:添加右边菜单并将Toolbar和drawerlayout进行整合

toolBar.inflateMenu(R.menu.toolbar_menu);//添加菜单
//导入V7的包,ToolbarDrawerLayout进行整合
ActionBarDrawerToggle drawerToggle=new ActionBarDrawerToggle(this,drawerLayout,toolBar,R.string.open,R.string.close);
drawerToggle.syncState();
drawerLayout.addDrawerListener(drawerToggle);




http://www.niftyadmin.cn/n/3649157.html

相关文章

vue使用jwt加密_如何使用Vue和Node构建轻量级发票应用程序:JWT身份验证和发送发票

vue使用jwt加密介绍 (Introduction) In the previous parts of the series, we looked at how to create the User Interface of our Invoicing Application that allowed users to create and view existing invoices. In this final part of the series, you will set up per…

TabLayout、ViewPager、fragment实现可滑动的顶部菜单

首先看下效果 第一步&#xff1a;主布局 <LinearLayoutandroid:layout_width"wrap_content"android:layout_height"wrap_content"android:orientation"vertical"><android.support.v7.widget.Toolbarandroid:id"id/tool_bar"…

node.js运行js_如何使用Node.js创建和运行计划的作业

node.js运行js介绍 (Introduction) Ever wanted to do specific things on your application server at certain times without having to manually run them yourself? This is where scheduled tasks come in handy. 是否曾经想过在特定时间在应用程序服务器上执行特定操作…

正确地做事与做正确的事同样重要

正确地做事与做正确的事同样重要一位软件工程师的6年总结作者&#xff1a;成晓旭http://blog.csdn.net/cxxsoft(声明&#xff1a;欢迎转载&#xff0c;请保证文章的完整性)“又是一年毕业时”&#xff0c;看到一批批学子离开人生的象牙塔&#xff0c;走上各自的工作岗位&#x…

recyclerView和retrofit的简单使用

第一步&#xff1a;导入相关包 //butterknife compile com.jakewharton:butterknife:8.4.0 annotationProcessor com.jakewharton:butterknife-compiler:8.4.0//retrofit compile com.squareup.retrofit2:retrofit:2.1.0 compile com.squareup.retrofit2:adapter-rxjava:2.1.0 …

Intent ACTION值自定义

在启动一个ACTIVITY时&#xff0c;作为信使的Intent主要由三部分构成&#xff1a;Intent<Action,Data,Category>&#xff1b;对于Action&#xff0c;有时候我们不一定非得用系统自定义的值&#xff0c;而可以自定义&#xff0c;同样可以达到启动其它Activity的效果。 这里…

函数式javascript_JavaScript函数式编程介绍:部分应用程序和库里

函数式javascript介绍 (Introduction) With the adoption of the Redux JavaScript library, the Reason syntax extension and toolchain, and the Cycle JavaScript framework, functional programming with JavaScript is becoming increasingly relevant. Two important id…

[C++]监控特定文件夹的事件:三种解决方法汇总

监控特定文件夹的事件&#xff1a;三种解决方法汇总LDBIVR程序中要监视特定文件夹的文件落地或者删除事件&#xff0c;本来要用SHELL中的事件通知机制&#xff0c;后来因为要考虑到各种意外事件&#xff0c;如服务意外退出、服务器崩溃等&#xff0c;遂作罢。对于目录事件异步通…