show drop down menu within/from action bar
show drop down menu within/from action bar
*/-->
pre {
background-color: #2f4f4f;line-height: 1.6;
FONT: 10.5pt Consola,"Bitstream Vera Sans", Courier New, helvetica;
color:wheat;
}
.h3 {
margin-left: 10pt;
}
show drop down menu within/from action bar
Solution
When you want to anchor popupmenu to ActionItem in ActionBar you need to find
view that renders ActionItem. Simple find view with findViewById() where id is
same as id of your menu item in xml.
DISPLAYING POPUP
public boolean onOptionsItemSelected(MenuItem item) {
// ...
View menuItemView = findViewById(R.id.menu_overflow); // SAME ID AS MENU ID
PopupMenu popupMenu = new PopupMenu(this, menuItemView);
popupMenu.inflate(R.menu.counters_overflow);
// ...
popupMenu.show();
// ...
return true;
}
MENU
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" > .... <item
android:id="@+id/menu_overflow"
android:icon="@drawable/ic_overflow"
android:showAsAction="ifRoom"
android:title="@string/menu_overflow"/> .... </menu>
or you can dynamically genereate the popup menu as this:
View menuItemView = findViewById(R.id.menu_dropdown); // SAME ID AS MENU ID PopupMenu popup = new PopupMenu(MainActivity.this, menuItemView); android.view.Menu menu = popup.getMenu();
menu.add("test").setOnMenuItemClickListener(new android.view.MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(android.view.MenuItem item) {
return true;
}
});
} popup.show();
There are more usage availble here.
Post by: Jalen Wang (转载请注明出处)
show drop down menu within/from action bar的更多相关文章
- Contextual Action bar(3) 两个示例
一.通过activity启动Context Action Bar 1.主java public class ActivityActionModeFrgmt extends Fragment imple ...
- Android 自定义title 之Action Bar
Android 自定义title 之Action Bar 2014-06-29 飞鹰飞龙... 摘自 博客园 阅 10519 转 25 转藏到我的图书馆 微信分享: Action Ba ...
- 【Android】Android之Action Bar
Action Bar是在窗口上指示用户位置的组件,同时给用户提供导航和操作.使用Action Bar可以让你的应用在不同配置的屏幕上看起来比较一致.在开始之前,先了解一些相关的术语: Action B ...
- Action Bar详解
Action bar是一个标识应用程序和用户位置的窗口功能,并且给用户提供操作和导航模式.在大多数的情况下,当你需要突出展现用户行为或全局导航的activity中使用action bar,因为acti ...
- Android开发之Action Bar
Action Bar代替了传统的位于设备屏幕的标题栏,主要用来显示应用程序的图标和活动的名称以及添加定制动作项等功能. 1. 显示和隐藏Action Bar 显示和隐藏Action Bar 一般有两种 ...
- Android Action Bar 详解篇 .
作者原创,转载请标明出处:http://blog.csdn.net/yuxlong2010 作为Android 3.0之后引入的新的对象,ActionBar可以说是一个方便快捷的导航神器.它可以作为活 ...
- (Android UI)Action Bar
Action Bar 指明用户当前所在的界面,添加多个功能性按键和下拉式选择框,以提供能多功能. 主题一:让应用具备ActionBar 可能条件一:Support Android 3.0(API 11 ...
- 安卓开发_浅谈Action Bar
一.Action Bar 导航栏.是3.0之后出现的. 所以注意使用的时候清单文件要设置下 android:minSdkVersion="11"(至少11) 但如果使用v4包,则不 ...
- 第三部分:Android 应用程序接口指南---第二节:UI---第四章 Action Bar
第4章 Action Bar Action Bar是一个能用于确定应用程序和用户的位置,并提供给用户操作和导航模式的窗口功能.如果需要显著地展示当前用户的操作或导航,应该使用Action Bar,因为 ...
随机推荐
- Google C++编程风格指南
作者:Hawstein 出处:http://hawstein.com/posts/google-cpp-style-guide.html 前言 越来越发现一致的编程风格的重要性,于是把Google的C ...
- MyBatis 拦截器 (实现分页功能)
由于业务关系 巴拉巴拉巴拉 好吧 简单来说就是 原来的业务是 需要再实现类里写 selectCount 和selectPage两个方法才能实现分页功能 现在想要达到效果是 只通过一个方法就可以实现 也 ...
- C#实现JSON序列化与反序列化介绍
方法一:引入System.Web.Script.Serialization命名空间使用 JavaScriptSerializer类实现简单的序列化 序列化类:Personnel public clas ...
- jquery完善的处理机制
使用jQuery选择器不仅比使用传统的getElementById()和getElementsByTagName()函数简洁得多,而且还能避免某些错误.请看下面例子: <script> d ...
- MySQL数据库添加一个字段
MySQL数据库添加一个字段 1.添加一个字段 alter table tableName add 列名 数据类型; 2.添加一个字段设置默认值 alter table tableName add ...
- Oracle死锁只会回滚跟死锁有关的那条SQL,而不会回滚整个事务
数据库检测到死锁后,只会回滚跟死锁有关的某条语句,而不会回滚整个事务. 创建测试环境:SQL> create table test1(id int,name char(1)); 表已创建. SQ ...
- iBatis系列一
XML iBatis可以使用xml来作为参数输入以及结果返回:这个功能的优势在于某些特定的场景:还有可以通过DOM方式来作为参数传递:但是这个方式应用的比较少,如果服务器是xml服务器可以采用这种方式 ...
- SVN - 基础知识
1. 术语 $ svn checkout URL [PATH] ----- 下载服务器所有文件 (clone) 到本地[path] --- 只需一次 $ svn checkout http: ...
- PADS故障解决
1. 点击PADS后就会出现以下: "The directory pointed by the FileDir INI file entry cannot be found.Aborting ...
- extjs中第一次访问有效,第二次访问出现部分组件无法显示的,动态改变组件的label值的方法,ExtJs中组件最好少使用ID属性(推荐更多使用Name属性)
在公司做的一个OA项目中,曾经就遇到了这样的一个问题:(我是在jsp中的div中将js render到div中去的)第一次访问此界面的时候,formpanel上的组件能正常显示,不刷新整个页面的前提下 ...