在actionbar中加入item的方法
首先在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的方法的更多相关文章
- 解决ActionBar中的item不显示在ActionBar的问题
今天在用ActionBar,需要增加一个菜单选项,按教程在/res/menu下对应的布局文件中添加了一个item,但是它却是显示在overflow中,而不是直接显示在ActionBar当中的.我的布局 ...
- ASP.NET 中DataGrid item 绑定方法
<Columns> <asp:TemplateColumn HeaderImageUrl="../../Images/delete.GIF"> <He ...
- Python中使用item()方法遍历字典的例子
Python中使用item()方法遍历字典的例子 这篇文章主要介绍了Python中使用item()方法遍历字典的例子,for...in这种是Python中最常用的遍历字典的方法了,需要的朋友可以参考下 ...
- Android ActionBar中的下拉菜单
在ActionBar中添加下拉菜单,主要有一下几个关键步骤: 1. 生成一个SpinnerAdapter,设置ActionBar的下拉菜单的菜单项 2. 实现ActionBar.OnNavigatio ...
- 【转】[教程]隐藏ActionBar中的MenuItem
原文网址:http://blog.csdn.net/appte/article/details/12104823 有时候我们需要在不同的时候改变ActionBar中MenuItem的项数,或者隐藏某些 ...
- [教程]隐藏ActionBar中的MenuItem
有时候我们需要在不同的时候改变ActionBar中MenuItem的项数,或者隐藏某些MenuItem,百度上找了很久没什好资料,还是Google了一下,StackOverFlow上有大神解决了. 先 ...
- JQuery中each()的使用方法说明
JQuery中each()的使用方法说明 对于jQuery对象,只是把each方法简单的进行了委托:把jQuery对象作为第一个参数传递给jQuery的each方法.换句话说:jQuery提供的eac ...
- (转载)MongoDB C#驱动中Query几个方法
MongoDB C#驱动中Query几个方法 Query.All("name", "a", "b");//通过多个元素来匹配数组 Query ...
- S5中新增的Array方法详细说明
ES5中新增的Array方法详细说明 by zhangxinxu from http://www.zhangxinxu.com 本文地址:http://www.zhangxinxu.com/wor ...
随机推荐
- Spring Boot 中全局异常处理器
Spring Boot 中全局异常处理器,就是把错误异常统一处理的方法.等价于Springmvc中的异常处理器. 步骤一:基于前面的springBoot入门小demo修改 步骤二:修改HelloCon ...
- Google protobuf序列化以及反序列化
序列化的目的是将对象持久化到硬盘或者用于网络传输.java也提供了序列化技术,非常简单,只要实现Serializable接口即可.如下: public class commonService impl ...
- DevExpress 给TreeList添加右键菜单
只有在右击节点时才会触发 private void treeList1_MouseDown(object sender, MouseEventArgs e) { if (e.Button == Mou ...
- MergeSortedArray,合并两个有序的数组
问题描述:You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold add ...
- 在eclipse下使用maven的配置
1 2 3 4 5 6 7 8 public class Shifty { public static void main(String[] args) { int i = 0 ...
- centos下tomcat自启动
一.在指定目录创建脚本并赋予755权限 vim /etc/init.d/tomcat #!/bin/bash # # kenny kenny.zhou@tom.com # /etc/rc.d/init ...
- Vector3函数理解-计算两向量之间的角度
1.已知两个向量dirA,dirB.Vector3 dirA = new Vector3(-1,1,0); Vector3 dirB = new Vector3(-1,1,1);2.使向量处于同一个平 ...
- eclipse导入android项目错误,项目名称上有红叉,但代码中无报错
首先,在项目上右键,属性,选择编译目标,选择android版本或把Android的版本调高一点.
- 【转】Chrome保存mht网页文件的方法 – 无需任何插件,完美!
本帖原文地址: http://www.ihacksoft.com/chrome-save-mht.html 昨天晚上想要搞定一个 WordPress 自定义文章类型的问题,吃完晚饭后一直呆在办公室里研 ...
- Redis 数据备份与恢复,安全,性能测试,客户端连接,管道技术,分区(四)
Redis 数据备份与恢复 Redis SAVE 命令用于创建当前数据库的备份. 语法 redis Save 命令基本语法如下: redis 127.0.0.1:6379> SAVE 实例 re ...