2013.12.03(6) ——— android ActionbarSherlockSample之ListNavigation

本文介绍了一个使用Action Bar Sherlock实现的Android应用样例,重点在于ListNavigation功能的实现,包括主题切换、列表视图导航模式设置及与主机活动的交互。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

2013.12.03(6) ——— android ActionbarSherlockSample之ListNavigation

package com.actionbarsherlock.sample.demos;

import android.content.Context;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.SherlockActivity;

public class ListNavigation extends SherlockActivity implements ActionBar.OnNavigationListener {
private TextView mSelected;
private String[] mLocations;

@Override
public void onCreate(Bundle savedInstanceState) {
setTheme(SampleList.THEME); //Used for theme switching in samples
super.onCreate(savedInstanceState);

setContentView(R.layout.list_navigation);
mSelected = (TextView)findViewById(R.id.text);

mLocations = getResources().getStringArray(R.array.locations);

Context context = getSupportActionBar().getThemedContext();
ArrayAdapter<CharSequence> list = ArrayAdapter.createFromResource(context, R.array.locations, R.layout.sherlock_spinner_item);
list.setDropDownViewResource(R.layout.sherlock_spinner_dropdown_item);

getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
getSupportActionBar().setListNavigationCallbacks(list, this);
}

@Override
public boolean onNavigationItemSelected(int itemPosition, long itemId) {
mSelected.setText("Selected: " + mLocations[itemPosition]);
return true;
}
}


getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);


设置导航样式,一共有三种样式:

/**
* Standard navigation mode. Consists of either a logo or icon
* and title text with an optional subtitle. Clicking any of these elements
* will dispatch onOptionsItemSelected to the host Activity with
* a MenuItem with item ID android.R.id.home.
*/
public static final int NAVIGATION_MODE_STANDARD = android.app.ActionBar.NAVIGATION_MODE_STANDARD;

/**
* List navigation mode. Instead of static title text this mode
* presents a list menu for navigation within the activity.
* e.g. this might be presented to the user as a dropdown list.
*/
public static final int NAVIGATION_MODE_LIST = android.app.ActionBar.NAVIGATION_MODE_LIST;

/**
* Tab navigation mode. Instead of static title text this mode
* presents a series of tabs for navigation within the activity.
*/
public static final int NAVIGATION_MODE_TABS = android.app.ActionBar.NAVIGATION_MODE_TABS;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值