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,因为 ...
随机推荐
- Spring in action笔记
耦合的两面性 一方面代码耦合难以测试,会出现打地鼠式的bug特性(修复一个bug,引发另一个bug) 另一方面耦合又是必须的,不同的类必须要进行适当的交互,才能实现功能. bean的四种装配方 ...
- python 自动化之路 day 面向对象基础
1.面向對象基础概述 面向过程: 根据业务逻辑从上到下垒代码(如果程序修改,对于依赖的过程都需要进行修改.) 函数式: 将某功能代码封装到函数中,如后便无需重复编写,仅需要调用函数即可 面向对象: 世 ...
- php安装中的错误
http://www.cnblogs.com/kristain/articles/3809243.html 借鉴php安装错误 2013-01-04 19:16:49 分类: 系统运维 环境: ...
- Spring---Web MVC关于前台传值转换问题
Cannot convert value of type [java.lang.String] to required type [java.util.List]. 问题在于:(String to E ...
- jQuery 快速入门教程
内容目录 jQuery 入门 什么是jQuery 如何使用jQuery jQuery的运行原理 如何选择jQuery版本 ready() 准备就绪时执行代码 jQuery 核心:选取元素 使用jQue ...
- html5 canvas绘制圆形印章,以及与页面交互
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- 微信分享功能引入页面-控制分享时候调用的标题、图片、url和微信按钮隐藏显示控制
1.设置分享调用的标题.图片.url预览. 2.控制右上角三个点按钮的隐藏显示(和底部工具栏的显示隐藏--未测试). 3.判断网页是否在微信中被调用. <!doctype html> &l ...
- Mac下安装Scrapy
执行 sudo pip install Scrapy 时会碰到libxml/xmlversion file no found 解决方法: brew install libxml2 brew insta ...
- Kafka Offset Storage
1.概述 目前,Kafka 官网最新版[0.10.1.1],已默认将消费的 offset 迁入到了 Kafka 一个名为 __consumer_offsets 的Topic中.其实,早在 0.8.2. ...
- SQL Server 2012 Features
SQL SQL Server 2012 新增加的几个函数: SELECT CONVERT (INT, 'Angkor-216.00') 直接报错 SELECT TRY_CONVERT(INT, 'SS ...