首先在menu文件夹中创建post.xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:title="发布"
app:showAsAction="ifRoom" />
</menu>

showAsAction=never会永远折叠在三个点里面,=ifRoom有空间会出来

orderInCategory 表示不折叠优先级

每个<item/>标签就添加一个item

然后在activity中加入

    @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_post);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar); }

然后override以下方法,注意R.menu.post和menu/post.xml同名

    @Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.post, menu);
return true;
}

在layout中加入

    <android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay"> <android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" /> </android.support.design.widget.AppBarLayout>

在actionbar中加入item的方法的更多相关文章

  1. 解决ActionBar中的item不显示在ActionBar的问题

    今天在用ActionBar,需要增加一个菜单选项,按教程在/res/menu下对应的布局文件中添加了一个item,但是它却是显示在overflow中,而不是直接显示在ActionBar当中的.我的布局 ...

  2. ASP.NET 中DataGrid item 绑定方法

    <Columns> <asp:TemplateColumn HeaderImageUrl="../../Images/delete.GIF"> <He ...

  3. Python中使用item()方法遍历字典的例子

    Python中使用item()方法遍历字典的例子 这篇文章主要介绍了Python中使用item()方法遍历字典的例子,for...in这种是Python中最常用的遍历字典的方法了,需要的朋友可以参考下 ...

  4. Android ActionBar中的下拉菜单

    在ActionBar中添加下拉菜单,主要有一下几个关键步骤: 1. 生成一个SpinnerAdapter,设置ActionBar的下拉菜单的菜单项 2. 实现ActionBar.OnNavigatio ...

  5. 【转】[教程]隐藏ActionBar中的MenuItem

    原文网址:http://blog.csdn.net/appte/article/details/12104823 有时候我们需要在不同的时候改变ActionBar中MenuItem的项数,或者隐藏某些 ...

  6. [教程]隐藏ActionBar中的MenuItem

    有时候我们需要在不同的时候改变ActionBar中MenuItem的项数,或者隐藏某些MenuItem,百度上找了很久没什好资料,还是Google了一下,StackOverFlow上有大神解决了. 先 ...

  7. JQuery中each()的使用方法说明

    JQuery中each()的使用方法说明 对于jQuery对象,只是把each方法简单的进行了委托:把jQuery对象作为第一个参数传递给jQuery的each方法.换句话说:jQuery提供的eac ...

  8. (转载)MongoDB C#驱动中Query几个方法

    MongoDB C#驱动中Query几个方法 Query.All("name", "a", "b");//通过多个元素来匹配数组 Query ...

  9. S5中新增的Array方法详细说明

      ES5中新增的Array方法详细说明 by zhangxinxu from http://www.zhangxinxu.com 本文地址:http://www.zhangxinxu.com/wor ...

随机推荐

  1. JAVA实现IP地址解析

    转载至:http://blog.csdn.net/dragontang/article/details/4151660 http://www.iteye.com/topic/340548#

  2. 关于file_get_contents返回False的问题

    在本地测试中,使用file_get_contents获取远程服务器的资源是可以的: public function send_post($url, $post_data = null) { $post ...

  3. NO.2 You must restart adb and Eclipse多种情形分析与解决方案

    一.问题描述:     运行android程序控制台输出     The connection to adb is down, and a severe error has occured.      ...

  4. 门户diy实现翻页功能的方法

    1.打开 \source\class\block\portal\block_article.php 文件 找到 function getdata($style, $parameter) 修改为 fun ...

  5. 分享知识-快乐自己:能使 Oracle 索引失效的六大限制条件

    Oracle 索引的目标是避免全表扫描,提高查询效率,但有些时候却适得其反. 例如一张表中有上百万条数据,对某个字段加了索引,但是查询时性能并没有什么提高,这可能是 oracle 索引失效造成的.or ...

  6. 如何查看电脑硬盘是gpt分区还是MBR分区

    首先我们右键点击 我的电脑 ,然后在弹出的快捷菜单中我们点击 管理,如下图: 然后在 计算机管理 对话框中,我们可以看到在左侧的存储下有一个 磁盘管理,这里我们点击 磁盘管理,如下图: 点击 磁盘管理 ...

  7. 51nod 1119 组合数,逆元

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1119 1119 机器人走方格 V2 基准时间限制:1 秒 空间限制:13 ...

  8. bootstrap 操作提示placeholder

    Javascript 部分 function checkForDefaultAlertPlaceholder() { if ($("#alertPlaceholder").leng ...

  9. 面向对象设计原则-SOLID

    SOLID的意思是: Single responsibility principle 单一职责原则 Open/close principle 开放/封闭原则 Liskov substitution p ...

  10. 远程登录MySQL

    mysql 远程连接数据库的二种方法   一.连接远程数据库: 1.显示密码 如:MySQL 连接远程数据库(192.168.5.116),端口“3306”,用户名为“root”,密码“123456” ...