在actionbar中加入item的方法
2015-11-19 01:50
357 查看
首先在menu文件夹中创建post.xml
showAsAction=never会永远折叠在三个点里面,=ifRoom有空间会出来
orderInCategory 表示不折叠优先级
每个<item/>标签就添加一个item
然后在activity中加入
然后override以下方法,注意R.menu.post和menu/post.xml同名
在layout中加入
<?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>
相关文章推荐
- 5.7 - Simple Car Example Using Functions
- 5.5 - Pass by Reference
- 5.4 - Args, Keywords Args and Defaults
- angular源码分析:angular中入境检察官$sce
- 5.3 - Return Statements
- 5.2 - Function Basics
- 5.1 - Introduction to Functions
- BufferedRead @ BuferedWrite 在Socket中的问题
- 4.6 - Maya Commands: select
- 4.5 - While Loops
- 基于Smack3.0.4+ Openfire3.10.2开发之Android 客户端之三
- 4.4 - For Loops
- 4.3 - Maya Commands: Errors and Warnings
- HTML5游戏制作之路_03_egret的资源加载机制
- Webkit之组成/Chrome组成
- 4.2.2 - Logical and/or Operators
- Webkit之理解webkit/chrome的目录结构
- 4.2.1 - Flow Control Using If/Else Statements
- Webkit之CSS基础介绍
- 缓冲区溢出攻击实验(二)