今天需要更改一个actionbar上的spinner的字体颜色,结果试了好长时间都没有解决,最后才发现,原来他是在代码下增加的一个textview,然后使用adapter加载的,并不是直接用framework下的布局。现在总结下spinner的使用方法,直接见下面的代码

1)首先要有一个spinneradapter来跟spinner进行数据加载

 private BaseAdapter mStackAdapter = new BaseAdapter() {
@Override
public int getCount() {
return mState.stack.size();
} @Override
public DocumentInfo getItem(int position) {
return mState.stack.get(mState.stack.size() - position - 1);
} @Override
public long getItemId(int position) {
return position;
} @Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.item_title, parent, false);
} final TextView title = (TextView) convertView.findViewById(android.R.id.title);
final DocumentInfo doc = getItem(position); if (position == 0) {
final RootInfo root = getCurrentRoot();
title.setText(root.title);
} else {
title.setText(doc.displayName);
} // No padding when shown in actionbar
convertView.setPadding(0, 0, 0, 0);
return convertView;
}
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.item_title, parent, false);
} final ImageView subdir = (ImageView) convertView.findViewById(R.id.subdir);
final TextView title = (TextView) convertView.findViewById(android.R.id.title);
final DocumentInfo doc = getItem(position); if (position == 0) {
final RootInfo root = getCurrentRoot();
title.setText(root.title);
subdir.setVisibility(View.GONE);
} else {
title.setText(doc.displayName);
subdir.setVisibility(View.VISIBLE);
} return convertView;
}
};

上面有两个比较重要的方法

一个是getview:这个方法是加载提示prompt用的

一个是getDropView:这个是加载下拉框用的

2)添加dropview点击监听事件

    private OnNavigationListener mStackListener = new OnNavigationListener() {
@Override
public boolean onNavigationItemSelected(int itemPosition, long itemId) {
if (mIgnoreNextNavigation) {
mIgnoreNextNavigation = false;
return false;
} while (mState.stack.size() > itemPosition + 1) {
mState.stackTouched = true;
mState.stack.pop();
}
onCurrentDirectoryChanged(ANIM_UP);
return true;
}
};

3)添加spinneradapter跟dropview

actionBar.setListNavigationCallbacks(mStackAdapter, mStackListener);
actionBar.setSelectedNavigationItem(mStackAdapter.getCount() - 1);

actionbar spinner-用法实例的更多相关文章

  1. php中的curl使用入门教程和常见用法实例

    摘要: [目录] php中的curl使用入门教程和常见用法实例 一.curl的优势 二.curl的简单使用步骤 三.错误处理 四.获取curl请求的具体信息 五.使用curl发送post请求 六.文件 ...

  2. 上传文件及$_FILES的用法实例

    Session变量($_SESSION):�php的SESSION函数产生的数据,都以超全局变量的方式,存放在$_SESSION变量中.1.Session简介SESSION也称为会话期,其是存储在服务 ...

  3. C++语言中cin cin.getline cin.get getline gets getchar 的用法实例

    #include <iostream> #include <string> using namespace std; //关于cin cin.getline cin.get g ...

  4. Union all的用法实例sql

    ---Union all的用法实例sqlSELECT TOP (100) PERCENT ID, bid_user_id, UserName, amount, createtime, borrowTy ...

  5. 【转】javascript入门系列演示·三种弹出对话框的用法实例

    对话框有三种 1:只是提醒,不能对脚本产生任何改变: 2:一般用于确认,返回 true 或者 false ,所以可以轻松用于 if...else...判断 3: 一个带输入的对话框,可以返回用户填入的 ...

  6. php strpos 用法实例教程

    定义和用法该strpos ( )函数返回的立场,首次出现了一系列内部其他字串. 如果字符串是没有发现,此功能返回FALSE . 语法 strpos(string,find,start) Paramet ...

  7. 【JSP】三种弹出对话框的用法实例

    对话框有三种 1:只是提醒,不能对脚本产生任何改变: 2:一般用于确认,返回 true 或者 false ,所以可以轻松用于 if...else...判断 3: 一个带输入的对话框,可以返回用户填入的 ...

  8. python多线程threading.Lock锁用法实例

    本文实例讲述了python多线程threading.Lock锁的用法实例,分享给大家供大家参考.具体分析如下: python的锁可以独立提取出来 mutex = threading.Lock() #锁 ...

  9. jQuery中on()方法用法实例详解

    这篇文章主要介绍了jQuery中on()方法用法,实例分析了on()方法的功能及各种常见的使用技巧,并对比分析了与bind(),live(),delegate()等方法的区别,需要的朋友可以参考下 本 ...

  10. IIS7 URL Rewrite 用法实例

    原文:IIS7 URL Rewrite 用法实例 很友好的URL地址,使访问的人很容易记住.要求你的用户记住" http://www.contoso.com/article.aspx?id= ...

随机推荐

  1. string类自定义字符串替换函数replace

    #include <iostream> #include <string> using namespace std; /* *  函数功能:将string字符串中的某些字符替换 ...

  2. orm 通用方法——DeleteModel 主键删除

    定义代码: /** * 描述:删除对象 * 作者:Tianqi * 日期:2014-09-17 * param:model 对象实例,包含主键 * return:int 受影响行数 * return: ...

  3. Java经典算法案例

    笔试中的编程题3 JAVA经典算法40例[程序1] 题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第四个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少? ...

  4. 联想杨天 S4130-12 win10改win7 bios参数设置

    一.进入bios 开机后按 F1 二.改bion参数 1.移动到 save& Exit  ,修改 OS optimized defaults   为“Disbled” 再 “F9” 保存 2. ...

  5. Deepin for Linux 下串口调试交换机

    最近因工作需要,在淘宝购买了一条宇泰的串口线:USB to RS232 之所以选择这款,主要是它支持 Windows.Linux.mac Linux机是Deepin for Linux,算是国产比较好 ...

  6. vim 跨文件复制

    我们都知道,当我们在一个文件之间进行复制粘贴的时候,vim提供给我们的方法非常多,三个模式下都有方法实现字符.句子.段落之间的复制粘贴.当时,如果我们想要在两个文件之间进行复制粘贴,这就有点麻烦了.我 ...

  7. ASP.Net MVC默认目录结构

    1.Controllers 保存处理URL请求的Controller类 2.Models 保存操纵业务与数据对象的类 3.Views 保存UI模板页面 4.Scripts 保存Javascript库文 ...

  8. android 获取蓝牙已连接设备

    蓝牙如果手动配对并已连接,获取连接的设备: 1.检测连接状态: int a2dp = bluetoothAdapter.getProfileConnectionState(BluetoothProfi ...

  9. Zabbix + Grafana

    Grafana 简介 Grafana自身并不存储数据,数据从其它地方获取.需要配置数据源 Grafana支持从Zabbix中获取数据 Grafana优化了图形的展现,可以用来做监控大屏 Grafana ...

  10. 使用无线局域网(WLAN)更需要注意加强安全防范

           下面链接介绍对WLAN的安全加密部分的内容,主要对WinAircrackPack工具的在Wlan方面的应用分析,介绍常见几种的加密方式,以及再使用无线设备时候的注意事项.650) thi ...