在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 ...
随机推荐
- Google maps API
https://developers.google.com/kml/documentation/kml_tuthttps://developers.google.com/maps/documentat ...
- Maven配置与创建
1.下载Maven工具 从maven官网下载:https://maven.apache.org/download.cgi apache-maven-x.x.x-bin.zip ,解压到指定目录,例如D ...
- PAT1036. Boys vs Girls (25)
#include <iostream> #include <algorithm> #include <vector> using namespace std; st ...
- 基于开源库jsoncpp的json字符串解析
json(JavaScript Object Notation)是一种轻量级高效数据交换格式.相比于XML,其更加简洁,解析更加方便.在实习期间,我负责的程序模块,多次使用到json进行数据传输.由于 ...
- JAVA中的数据存储(堆及堆栈)- 转载
1.寄存器:最快的存储区, 由编译器根据需求进行分配,我们在程序中无法控制.2. 栈:存放基本类型的变量数据和对象的引用,但对象本身不存放在栈中,而是存放在堆(new 出来的对象)或者常量池中(对象可 ...
- LengthOfLastWord,字符串最后一个子串的长度
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the l ...
- Pow,求x的y次幂
算法分析:很显然用递归.但是直接用递归会造成栈溢出,时间复杂度是o(n).所以要用分治思想,时间复杂度是o(logN). public class Power { //栈溢出,时间复杂度是o(n) p ...
- Memcached add 命令
Memcached add 命令用于将 value(数据值) 存储在指定的 key(键) 中. 如果 add 的 key 已经存在,则不会更新数据,之前的值将仍然保持相同,并且您将获得响应 NOT_S ...
- Cacti的基本安装配置
////////////////////cacti///////////////////////////常用的监控软件有:cacti.nagios.zabbix等 cacti 重图形.有数据历史.需要 ...
- css滚动相关问题记录
1) 关于滑动加速优化,可以通过css进行处理 例如,html如下: <div class="content-dialog"> <h1>活动规则</h ...