Careless Me
我在百度知道上提了一个问题:
如图我在menu.xml里试图加一个search的按钮,但我从网页上复制了图中第二个item里的代码,运行的时候,这个item却总是出现在overflow(下拉菜单)里面,不出现在action bar。而我用手打出第一个item里的代码之后,却可以在action bar上显示。这是为什么?两段代码完全一样啊。

这两段代码我调了很久。最后看来看去,发现这个段代码并不是「完全一样」。
showAsAction属性之前的命名空间,一个是android,一个是app。结果就导致没有使用命名空间的下面的item无效。
那为什么其他的android打头的代码有效?来看看完整的menu头:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.larry.projecty.MainActivity" >
android对应的空间是/apk/res/android,而app对应/apk/res-auto.而android developers上,也就我复制的那段代码的来源,只用了这一个命名空间:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
我TM已经糊涂了。I don't get the fuck.好吧,我就用app做命名空间好了。草。
草。搞这些SB代码,这个JB细节搞了一晚上,结果这只是一堆错误中的一个。想弄懂所有一切,哪有那么多精力和时间??真JB累。
干。
----------------------------------------------
冷静了一会儿,想起来原来为了支持2.x系统而用自己的命名空间。
查了一下,网上说:
「这是告诉系统,showAsAction使用library的XML attributes。」
也就是说在用其他的library的时候要用自己的命名空间。
此外还有:
yourapp:actionViewClass="android.support.v7.widget.SearchView"
yourapp:actionProviderClass="android.support.v7.widget.ShareActionProvider"
我操,一箭双雕,正好解决了为什么得不到search view的问题了。
除了在xml里改命名空间,在MainActivity.java里也要改import哦,改成:
import android.support.v7.widget.SearchView;
操,好高兴。
可怜的程序狗啊。
参考:
http://blog.csdn.net/tianjf0514/article/details/13278539
Careless Me的更多相关文章
- I would I were a careless child
I would I were a careless child by George Gordon Byron 1 I would I were a careless child, still dwel ...
- [COPY] How to become a hacker
Engish version copied from here Why This Document? As editor of the Jargon File and author of a few ...
- SCI/EI期刊投稿 Reply Letter 常用格式总结
SCI/EI期刊投稿Reply Letter常用格式总结 整个论文投稿的过程中,会遇到各种问题,需要我们向主编询问或是回复.下面主要总结了responses to the comme ...
- Flume interceptor 使用注意事项
1. 在使用 Regex Filtering Interceptor的时候一个属性是excludeEvents 当它的值为true 的时候,过滤掉匹配到当前正则表达式的一行 当它的值为false的时候 ...
- Error Handling
Use Exceptions Rather Than Return Codes Back in the distant past there were many languages that didn ...
- RFID 仿真/模拟/监控/拦截/检测/嗅探器
Sound card based RFID sniffer/emulator (Too tired after recon.cx to do draw the schematics better th ...
- RFID 读写器 Reader Writer Cloner
RFID读写器的工作原理 RFID的数据采集以读写器为主导,RFID读写器是一种通过无线通信,实现对标签识别和内存数据的读出和写入操作的装置. 读写器又称为阅读器或读头(Reader).查询器(Int ...
- 2015年第4本(英文第3本):Godfather教父
2015年的第4本书,第3本英文书. 书名:Godfather ,中文书名<教父> 作者: Mario Puzo 单词数:17万 词汇量:1万 首万词不重复词数:2200(这个我不太相信) ...
- sdut 2411:Pixel density(第三届山东省省赛原题,字符串处理)
Pixel density Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Pixels per inch (PPI) or pi ...
随机推荐
- Understand the Business Domain
 Understand the Business Domain Mark Richards EFFECTivE SoFTWARE ARCHiTECTS understand not only tec ...
- vue-router 的URL路径中#的意义
传送门 https://router.vuejs.org/zh-c... Router 构造配置 routes 类型: Array<RouteConfig> RouteConfig 的类型 ...
- Redis安装过程
Redis在windows下安装过程 学习了:https://www.cnblogs.com/M-LittleBird/p/5902850.html 学习了:http://www.runoob.com ...
- Html5学习笔记1 元素 标签 属性
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Objective C block背后的黑魔法
前言 block在Objective C开发中应用非常广泛,我们知道block会捕获外部对象,也知道使用block要防止循环引用. "知其然而不知其所以然"是一件非常痛苦的事情,那 ...
- HRBUST2030(dfs)
成语接龙 Time Limit: 1000 MS Memory Limit: 32768 KB 64-bit integer IO format: %lld , %llu Java class nam ...
- [转]si设置
好吧,我有代码格式的强迫症,代码不整齐,我看的都头疼,之前一直喜欢用SourceStyler C++的,但是这个在win7下貌似不能使用,只能转向astyle了. http://www.cnblogs ...
- Mysql启动自己主动设置max_connections为其它值
背景 有同学反应.产品连不上,登陆到server.发现连接数不够了. 接着先重新启动mysql,发如今mysql启动的时候会报Waring Warning Changed limits: max_op ...
- Android------Intent.createChooser
Intent的匹配过程中有三个步骤,包含Action , category与data 的匹配. 假设匹配出了多个结果.系统会显示一个dialog让用户来选 择.例如以下图: 那么今天我们主要是解 ...
- Hadoop集群_Hadoop安装配置
1.集群部署介绍 1.1 Hadoop简介 Hadoop是Apache软件基金会旗下的一个开源分布式计算平台.以Hadoop分布式文件系统(HDFS,Hadoop Distributed Filesy ...