public abstract class ActionBar
extends Object
| java.lang.Object | |
| android.support.v7.app.ActionBar | |
活动中的主要工具栏,可显示活动标题,应用程序级导航可供件和其他交互项目。
当活动使用AppCompat的AppCompat主题(或其后代主题之一)时,操作栏将出现在活动窗口的顶部。 否则,您可以通过调用requestFeature(FEATURE_SUPPORT_ACTION_BAR)或使用windowActionBar属性在自定义主题中声明它来添加操作栏。
操作栏可以由应用程序布局中的任何工具栏小部件表示。 应用程序可能会向Activity发出信号,表明应将哪个工具栏视为活动的操作栏。 使用此功能的活动应使用提供的.NoActionBar主题之一,将windowActionBar属性设置为false或以其他方式不请求窗口功能。
如果您的活动具有选项菜单,则可以将选定项目直接从操作栏访问为“操作项目”。 您还可以修改操作栏的各种特征或完全删除它。
导航按钮(以前称为“主页”)接管了之前由应用程序图标占用的空间。 希望表达更强大品牌的应用程序应该在操作栏和其他应用程序镶边中大量使用其品牌颜色,或者使用logo代替其标准标题文本。
在您的活动中,您可以通过调用 getSupportActionBar() getSupportActionBar()}来检索 ActionBar的实例。
在某些情况下,可以使用ActionMode将操作栏覆盖在启用上下文操作的其他栏上。 例如,当用户在您的活动中选择一个或多个项目时,可以启用一个操作模式,该模式提供特定于所选项目的操作,并使用临时替换操作栏的UI。 尽管UI可占据相同的空间,所述ActionMode API是从那些不同的和独立ActionBar 。
有关如何使用操作栏的信息,包括如何添加操作项目,导航模式等,请阅读 Action Bar开发人员指南。
Nested classes |
|
|---|---|
class |
ActionBar.LayoutParams 与操作栏自定义视图关联的每个孩子的布局信息。 |
interface |
ActionBar.OnMenuVisibilityListener 监听器用于在显示或隐藏操作栏菜单时接收事件。 |
interface |
ActionBar.OnNavigationListener 此接口已弃用。 内置工具栏操作栏不支持操作栏导航模式。 考虑改用其他common navigation patterns 。 |
class |
ActionBar.Tab 这个类已被弃用。 内置工具栏操作栏不支持操作栏导航模式。 考虑改用其他common navigation patterns 。 |
interface |
ActionBar.TabListener 此接口已弃用。 内置工具栏操作栏不支持操作栏导航模式。 考虑改用其他common navigation patterns 。 |
常量(Constants) |
|
|---|---|
int |
DISPLAY_HOME_AS_UP 显示“家”元素,使其显示为“上”的可供选择。 |
int |
DISPLAY_SHOW_CUSTOM 显示自定义视图,如果已经设置。 |
int |
DISPLAY_SHOW_HOME 在此操作栏中显示“家”元素,为其他导航元素留出更多空间。 |
int |
DISPLAY_SHOW_TITLE 显示活动标题和副标题(如果有)。 |
int |
DISPLAY_USE_LOGO 如果可用,请使用徽标而不是图标。 |
int |
NAVIGATION_MODE_LIST 这个常数已被弃用。 内置工具栏操作栏不支持操作栏导航模式。 考虑改用其他common navigation patterns 。 |
int |
NAVIGATION_MODE_STANDARD 这个常数已被弃用。 内置工具栏操作栏不支持操作栏导航模式。 考虑使用其他common navigation patterns来代替。 |
int |
NAVIGATION_MODE_TABS 这个常数已被弃用。 内置工具栏操作栏不支持操作栏导航模式。 考虑使用其他common navigation patterns来代替。 |
Public constructors |
|
|---|---|
ActionBar() |
|
公共方法(Public methods) |
|
|---|---|
abstract void |
addOnMenuVisibilityListener(ActionBar.OnMenuVisibilityListener listener) 添加一个将响应菜单可见性更改事件的侦听器。 |
abstract void |
addTab(ActionBar.Tab tab, int position) 此方法已弃用。 内置工具栏操作栏不支持操作栏导航模式。 考虑改用其他common navigation patterns 。 |
abstract void |
addTab(ActionBar.Tab tab) 此方法已弃用。 内置工具栏操作栏不支持操作栏导航模式。 考虑改用其他common navigation patterns 。 |
abstract void |
addTab(ActionBar.Tab tab, int position, boolean setSelected) 此方法已弃用。 内置工具栏操作栏不支持操作栏导航模式。 考虑改用其他common navigation patterns 。 |
abstract void |
addTab(ActionBar.Tab tab, boolean setSelected) 此方法已弃用。 内置工具栏操作栏不支持操作栏导航模式。 考虑使用其他common navigation patterns来代替。 |
abstract View |
getCustomView() |
abstract int |
getDisplayOptions() |
float |
getElevation() 以像素为单位获取操作栏的Z轴高程。 |
abstract int |
getHeight() 检索ActionBar的当前高度。 |
int |
getHideOffset() 返回操作栏的当前垂直偏移量。 |
abstract int |
getNavigationItemCount() 此方法已弃用。 内置工具栏操作栏不支持操作栏导航模式。 考虑使用其他common navigation patterns来代替。 |
abstract int |
getNavigationMode() 此方法已弃用。 内置工具栏操作栏不支持操作栏导航模式。 考虑使用其他common navigation patterns来代替。 |
abstract int |
getSelectedNavigationIndex() 此方法已弃用。 内置工具栏操作栏不支持操作栏导航模式。 考虑改用其他common navigation patterns 。 |
abstract ActionBar.Tab |
getSelectedTab() 此方法已弃用。 内置工具栏操作栏不支持操作栏导航模式。 考虑使用其他common navigation patterns来代替。 |
abstract CharSequence |
getSubtitle() 以标准模式返回当前的ActionBar字幕。 |
abstract ActionBar.Tab |
getTabAt(int index) 此方法已弃用。 内置工具栏操作栏不支持操作栏导航模式。 考虑改用其他common navigation patterns 。 |
abstract int |
getTabCount() 此方法已弃用。 内置工具栏操作栏不支持操作栏导航模式。 考虑改用其他common navigation patterns 。 |
Context |
getThemedContext() 用适当的主题返回 |
abstract CharSequence |
getTitle() 在标准模式下返回当前的ActionBar标题。 |
abstract void |
hide() 如果它正在显示,请隐藏ActionBar。 |
boolean |
isHideOnContentScrollEnabled() 返回操作栏是否配置为与 |
abstract boolean |
isShowing() |
abstract ActionBar.Tab |
newTab() 此方法已弃用。 内置工具栏操作栏不支持操作栏导航模式。 考虑使用其他common navigation patterns来代替。 |
abstract void |
removeAllTabs() 此方法已弃用。 内置工具栏操作栏不支持操作栏导航模式。 考虑改用其他common navigation patterns 。 |
abstract void |
removeOnMenuVisibilityListener(ActionBar.OnMenuVisibilityListener listener) 删除菜单可见性侦听器。 |
abstract void |
removeTab(ActionBar.Tab tab) 此方法已弃用。 内置工具栏操作栏不支持操作栏导航模式。 考虑改用其他common navigation patterns 。 |
abstract void |
removeTabAt(int position) 此方法已弃用。 内置工具栏操作栏不支持操作栏导航模式。 考虑改用其他common navigation patterns 。 |
abstract void |
selectTab(ActionBar.Tab tab) 此方法已弃用。 内置工具栏操作栏不支持操作栏导航模式。 考虑使用其他common navigation patterns来代替。 |
abstract void |
setBackgroundDrawable(Drawable d) 设置ActionBar的背景。 |
abstract void |
setCustomView(View view) 将操作栏设置为自定义导航模式,为自定义导航提供视图。 |
abstract void |
setCustomView(int resId) 将操作栏设置为自定义导航模式,为自定义导航提供视图。 |
abstract void |
setCustomView(View view, ActionBar.LayoutParams layoutParams) 将操作栏设置为自定义导航模式,为自定义导航提供视图。 |
abstract void |
setDisplayHomeAsUpEnabled(boolean showHomeAsUp) 设置家庭是否应该显示为“up”的可供选择性。 |
abstract void |
setDisplayOptions(int options, int mask) 设置选定的显示选项。 |
abstract void |
setDisplayOptions(int options) 设置显示选项。 |
abstract void |
setDisplayShowCustomEnabled(boolean showCustom) 设置是否应显示自定义视图(如果已设置)。 |
abstract void |
setDisplayShowHomeEnabled(boolean showHome) 设置是否将应用程序主页示功表包含在操作栏中。 |
abstract void |
setDisplayShowTitleEnabled(boolean showTitle) 设置是否显示活动标题/副标题。 |
abstract void |
setDisplayUseLogoEnabled(boolean useLogo) 设置是否显示活动徽标而不是活动图标。 |
void |
setElevation(float elevation) 以像素为单位设置操作栏的Z轴高程。 |
void |
setHideOffset(int offset) 设置操作栏的当前隐藏偏移量。 |
void |
setHideOnContentScrollEnabled(boolean hideOnContentScroll) 在内容滚动中启用隐藏操作栏。 |
void |
setHomeActionContentDescription(CharSequence description) 设置Home / Up操作的备用描述。 |
void |
setHomeActionContentDescription(int resId) 设置Home / Up操作的备用描述。 |
void |
setHomeAsUpIndicator(int resId) 当启用 |
void |
setHomeAsUpIndicator(Drawable indicator) 当启用 |
void |
setHomeButtonEnabled(boolean enabled) 启用或禁用操作栏角落中的“主页”按钮。 |
abstract void |
setIcon(Drawable icon) 将图标设置为显示在操作栏的“主页”部分。 |
abstract void |
setIcon(int resId) 将图标设置为显示在操作栏的“主页”部分。 |
abstract void |
setListNavigationCallbacks(SpinnerAdapter adapter, ActionBar.OnNavigationListener callback) 此方法已弃用。 内置工具栏操作栏不支持操作栏导航模式。 考虑改用其他common navigation patterns 。 |
abstract void |
setLogo(int resId) 将徽标设置为显示在操作栏的“主页”部分。 |
abstract void |
setLogo(Drawable logo) 将徽标设置为显示在操作栏的“主页”部分。 |
abstract void |
setNavigationMode(int mode) 此方法已弃用。 内置工具栏操作栏不支持操作栏导航模式。 考虑使用其他common navigation patterns来代替。 |
abstract void |
setSelectedNavigationItem(int position) 此方法已弃用。 内置工具栏操作栏不支持操作栏导航模式。 考虑改用其他common navigation patterns 。 |
void |
setSplitBackgroundDrawable(Drawable d) 设置ActionBar的分割背景。 |
void |
setStackedBackgroundDrawable(Drawable d) 设置ActionBar的堆叠背景。 |
abstract void |
setSubtitle(CharSequence subtitle) 设置操作栏的副标题。 |
abstract void |
setSubtitle(int resId) 设置操作栏的副标题。 |
abstract void |
setTitle(CharSequence title) 设置操作栏的标题。 |
abstract void |
setTitle(int resId) 设置操作栏的标题。 |
abstract void |
show() 显示ActionBar,如果它当前不显示。 |
继承方法(Inherited methods) |
|
|---|---|
java.lang.Object
|
|
int DISPLAY_HOME_AS_UP
显示“家”元素,使其显示为“上”的可供选择。 例如,向左侧显示一个箭头,指示将采取的行动。 如果选择操作栏中的“主页”按钮,将其设置为在用户界面中以单个级别返回,而不是返回顶层或首页,请设置此标志。
设置此选项将隐式启用与home / up按钮的交互。 见setHomeButtonEnabled(boolean) 。
常量值:4(0x00000004)
int DISPLAY_SHOW_CUSTOM
显示自定义视图,如果已经设置。
常量值:16(0x00000010)
int DISPLAY_SHOW_HOME
在此操作栏中显示“家”元素,为其他导航元素留出更多空间。 这包括徽标和图标。
常量值:2(0x00000002)
int DISPLAY_SHOW_TITLE
显示活动标题和副标题(如果有)。
也可以看看:
常量值:8(0x00000008)
int DISPLAY_USE_LOGO
如果可用,请使用徽标而不是图标。 此标志将导致适当的导航模式使用更广泛的标志代替标准图标。
常数值:1(0x00000001)
int NAVIGATION_MODE_LIST
这个常数已被弃用。
内置工具栏操作栏不支持操作栏导航模式。 考虑改用其他common navigation patterns 。
列表导航模式。 该模式不是静态标题文本,而是在活动中提供用于导航的列表菜单。 例如,这可能会以下拉列表的形式呈现给用户。
常数值:1(0x00000001)
int NAVIGATION_MODE_STANDARD
这个常数已被弃用。
内置工具栏操作栏不支持操作栏导航模式。 考虑使用其他common navigation patterns来代替。
标准导航模式。 包含徽标或图标和标题文字以及可选的字幕。 单击这些元素中的任何一个将使用项目ID android.R.id.home的MenuItem将onOptionsItemSelected派发到主机Activity。
常量值:0(0x00000000)
int NAVIGATION_MODE_TABS
这个常数已被弃用。
内置工具栏操作栏不支持操作栏导航模式。 考虑改用其他common navigation patterns 。
Tab导航模式。 此模式不是静态标题文本,而是在活动中提供一系列导航栏。
常量值:2(0x00000002)
ActionBar ()
void addOnMenuVisibilityListener (ActionBar.OnMenuVisibilityListener listener)
添加一个将响应菜单可见性更改事件的侦听器。
| 参数(Parameters) | |
|---|---|
listener |
ActionBar.OnMenuVisibilityListener: The new listener to add |
void addTab (ActionBar.Tab tab, int position)
此方法已弃用。
内置工具栏操作栏不支持操作栏导航模式。 考虑改用其他common navigation patterns 。
添加选项卡以在选项卡式导航模式下使用。 该标签将插入position 。 如果这是要添加的第一个选项卡,它将成为选定的选项卡。
| 参数(Parameters) | |
|---|---|
tab |
ActionBar.Tab: The tab to add |
position |
int: The new position of the tab |
void addTab (ActionBar.Tab tab)
此方法已弃用。
内置工具栏操作栏不支持操作栏导航模式。 考虑改用其他common navigation patterns 。
添加选项卡以在选项卡式导航模式下使用。 该选项卡将添加到列表的末尾。 如果这是要添加的第一个选项卡,它将成为选定的选项卡。
| 参数(Parameters) | |
|---|---|
tab |
ActionBar.Tab: Tab to add |
void addTab (ActionBar.Tab tab, int position, boolean setSelected)
此方法已弃用。
内置工具栏操作栏不支持操作栏导航模式。 考虑使用其他common navigation patterns来代替。
添加选项卡以在选项卡式导航模式下使用。 该标签将在position处进行position 。
| 参数(Parameters) | |
|---|---|
tab |
ActionBar.Tab: The tab to add |
position |
int: The new position of the tab |
setSelected |
boolean: True if the added tab should become the selected tab. |
void addTab (ActionBar.Tab tab, boolean setSelected)
此方法已弃用。
内置工具栏操作栏不支持操作栏导航模式。 考虑改用其他common navigation patterns 。
添加选项卡以在选项卡式导航模式下使用。 该选项卡将添加到列表的末尾。
| 参数(Parameters) | |
|---|---|
tab |
ActionBar.Tab: Tab to add |
setSelected |
boolean: True if the added tab should become the selected tab. |
int getDisplayOptions ()
| 返回(Returns) | |
|---|---|
int |
The current set of display options. |
float getElevation ()
以像素为单位获取操作栏的Z轴高程。
操作栏的高程是它从其父表面放置的距离。 较高的值更接近用户。
| 返回(Returns) | |
|---|---|
float |
Elevation value in pixels |
int getHeight ()
检索ActionBar的当前高度。
| 返回(Returns) | |
|---|---|
int |
The ActionBar's height |
int getHideOffset ()
返回操作栏的当前垂直偏移量。
操作栏的当前隐藏偏移量是操作栏当前以像素为单位滚动离屏的距离。 有效范围为0(完全可见)到操作栏当前测量的height (完全不可见)。
| 返回(Returns) | |
|---|---|
int |
The action bar's offset toward its fully hidden state in pixels |
int getNavigationItemCount ()
此方法已弃用。
内置工具栏操作栏不支持操作栏导航模式。 考虑使用其他common navigation patterns来代替。
获取当前导航模式下存在的导航项目数量。
| 返回(Returns) | |
|---|---|
int |
Number of navigation items. |
int getNavigationMode ()
此方法已弃用。
内置工具栏操作栏不支持操作栏导航模式。 考虑使用其他common navigation patterns来代替。
返回当前的导航模式。 结果将是以下之一:
| 返回(Returns) | |
|---|---|
int |
The current navigation mode. |
int getSelectedNavigationIndex ()
此方法已弃用。
内置工具栏操作栏不支持操作栏导航模式。 考虑改用其他common navigation patterns 。
以列表或标签导航模式获取所选导航项目的位置。
| 返回(Returns) | |
|---|---|
int |
Position of the selected item. |
ActionBar.Tab getSelectedTab ()
此方法已弃用。
内置工具栏操作栏不支持操作栏导航模式。 考虑使用其他common navigation patterns来代替。
如果处于选项卡式导航模式且至少存在一个选项卡,则返回当前选定的选项卡。
| 返回(Returns) | |
|---|---|
ActionBar.Tab |
The currently selected tab or null |
CharSequence getSubtitle ()
以标准模式返回当前的ActionBar字幕。 如果getNavigationMode()不返回NAVIGATION_MODE_STANDARD则返回null。
| 返回(Returns) | |
|---|---|
CharSequence |
The current ActionBar subtitle or null. |
ActionBar.Tab getTabAt (int index)
此方法已弃用。
内置工具栏操作栏不支持操作栏导航模式。 考虑使用其他common navigation patterns 。
返回指定索引处的选项卡。
| 参数(Parameters) | |
|---|---|
index |
int: Index value in the range 0-get |
| 返回(Returns) | |
|---|---|
ActionBar.Tab |
|
int getTabCount ()
此方法已弃用。
内置工具栏操作栏不支持操作栏导航模式。 考虑改用其他common navigation patterns 。
返回当前在操作栏中注册的选项卡数量。
| 返回(Returns) | |
|---|---|
int |
Tab count |
Context getThemedContext ()
用适当的主题返回Context ,用于创建将出现在操作栏中的视图。 如果您正在充气或实例化将出现在操作栏中的自定义视图,则应该使用此方法返回的上下文。 (这包括用于列表导航模式的适配器。)这将确保视图与操作栏对比。
| 返回(Returns) | |
|---|---|
Context |
A themed Context for creating views |
CharSequence getTitle ()
在标准模式下返回当前的ActionBar标题。 如果getNavigationMode()不返回NAVIGATION_MODE_STANDARD则返回null。
| 返回(Returns) | |
|---|---|
CharSequence |
The current ActionBar title or null. |
void hide ()
如果它正在显示,请隐藏ActionBar。 如果承载ActionBar的窗口没有功能FEATURE_ACTION_BAR_OVERLAY ,它将调整应用程序内容的大小以适应新的可用空间。
不要直接调用此函数,还可以使用叠加功能使ActionBar通过View.SYSTEM_UI_FLAG_FULLSCREEN隐藏。 通过此系统UI标志隐藏ActionBar可以让您更加无缝地将其与其他屏幕装饰一起隐藏。
boolean isHideOnContentScrollEnabled ()
返回操作栏是否配置为与 nested scrolling child一起滚动到视线 nested scrolling child 。
| 返回(Returns) | |
|---|---|
boolean |
true if hide-on-content-scroll is enabled |
boolean isShowing ()
| 返回(Returns) | |
|---|---|
boolean |
true if the ActionBar is showing, false otherwise. |
ActionBar.Tab newTab ()
此方法已弃用。
内置工具栏操作栏不支持操作栏导航模式。 考虑改用其他common navigation patterns 。
创建并返回一个新的ActionBar.Tab 。 该标签在添加之前不会包含在操作栏中。
通常,制表符将用于在Fragment对象之间Fragment 。 以下是这些选项卡的典型实现:
import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.widget.Toast;
/**
* This demonstrates the use of action bar tabs and how they interact
* with other action bar features.
*/
public class FragmentTabs extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final ActionBar bar = getActionBar();
bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
bar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE);
bar.addTab(bar.newTab()
.setText("Simple")
.setTabListener(new TabListener<FragmentStack.CountingFragment>(
this, "simple", FragmentStack.CountingFragment.class)));
bar.addTab(bar.newTab()
.setText("Contacts")
.setTabListener(new TabListener<LoaderCursor.CursorLoaderListFragment>(
this, "contacts", LoaderCursor.CursorLoaderListFragment.class)));
bar.addTab(bar.newTab()
.setText("Apps")
.setTabListener(new TabListener<LoaderCustom.AppListFragment>(
this, "apps", LoaderCustom.AppListFragment.class)));
bar.addTab(bar.newTab()
.setText("Throttle")
.setTabListener(new TabListener<LoaderThrottle.ThrottledLoaderListFragment>(
this, "throttle", LoaderThrottle.ThrottledLoaderListFragment.class)));
if (savedInstanceState != null) {
bar.setSelectedNavigationItem(savedInstanceState.getInt("tab", 0));
}
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putInt("tab", getActionBar().getSelectedNavigationIndex());
}
public static class TabListener<T extends Fragment> implements ActionBar.TabListener {
private final Activity mActivity;
private final String mTag;
private final Class<T> mClass;
private final Bundle mArgs;
private Fragment mFragment;
public TabListener(Activity activity, String tag, Class<T> clz) {
this(activity, tag, clz, null);
}
public TabListener(Activity activity, String tag, Class<T> clz, Bundle args) {
mActivity = activity;
mTag = tag;
mClass = clz;
mArgs = args;
// Check to see if we already have a fragment for this tab, probably
// from a previously saved state. If so, deactivate it, because our
// initial state is that a tab isn't shown.
mFragment = mActivity.getFragmentManager().findFragmentByTag(mTag);
if (mFragment != null && !mFragment.isDetached()) {
FragmentTransaction ft = mActivity.getFragmentManager().beginTransaction();
ft.detach(mFragment);
ft.commit();
}
}
public void onTabSelected(Tab tab, FragmentTransaction ft) {
if (mFragment == null) {
mFragment = Fragment.instantiate(mActivity, mClass.getName(), mArgs);
ft.add(android.R.id.content, mFragment, mTag);
} else {
ft.attach(mFragment);
}
}
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
if (mFragment != null) {
ft.detach(mFragment);
}
}
public void onTabReselected(Tab tab, FragmentTransaction ft) {
Toast.makeText(mActivity, "Reselected!", Toast.LENGTH_SHORT).show();
}
}
}
| 返回(Returns) | |
|---|---|
ActionBar.Tab |
A new Tab |
也可以看看:
void removeAllTabs ()
此方法已弃用。
内置工具栏操作栏不支持操作栏导航模式。 考虑使用其他common navigation patterns来代替。
从操作栏中删除所有选项卡并取消选择当前选项卡。
void removeOnMenuVisibilityListener (ActionBar.OnMenuVisibilityListener listener)
删除菜单可见性侦听器。 该监听器将不再接收菜单可见性更改事件。
| 参数(Parameters) | |
|---|---|
listener |
ActionBar.OnMenuVisibilityListener: A listener to remove that was previously added |
void removeTab (ActionBar.Tab tab)
此方法已弃用。
内置工具栏操作栏不支持操作栏导航模式。 考虑改用其他common navigation patterns 。
从操作栏中删除一个选项卡。 如果选择了删除的选项卡,则将取消选择该选项卡,如果存在,则会选择另一个选项卡。
| 参数(Parameters) | |
|---|---|
tab |
ActionBar.Tab: The tab to remove |
void removeTabAt (int position)
此方法已弃用。
内置工具栏操作栏不支持操作栏导航模式。 考虑使用其他common navigation patterns来代替。
从操作栏中删除一个选项卡。 如果选择了删除的选项卡,则将取消选择该选项卡,如果存在,则会选择另一个选项卡。
| 参数(Parameters) | |
|---|---|
position |
int: Position of the tab to remove |
void selectTab (ActionBar.Tab tab)
此方法已弃用。
内置工具栏操作栏不支持操作栏导航模式。 考虑使用其他common navigation patterns 。
选择指定的选项卡。 如果它不是此操作栏的子项,它将被添加。
注意:如果您想按索引选择,请使用 setSelectedNavigationItem(int) 。
| 参数(Parameters) | |
|---|---|
tab |
ActionBar.Tab: Tab to select |
void setBackgroundDrawable (Drawable d)
设置ActionBar的背景。 这将用于主要操作栏。
| 参数(Parameters) | |
|---|---|
d |
Drawable: Background drawable |
void setCustomView (View view)
将操作栏设置为自定义导航模式,为自定义导航提供视图。 自定义导航视图显示在应用程序图标和任何操作按钮之间,可以使用任何可用的空间。 自定义导航视图的常见用例可能包括浏览器的自动建议地址栏或其他导航机制,这些机制不能很好地转换为提供的导航模式。
| 参数(Parameters) | |
|---|---|
view |
View: Custom navigation view to place in the ActionBar. |
void setCustomView (int resId)
将操作栏设置为自定义导航模式,为自定义导航提供视图。
自定义导航视图显示在应用程序图标和任何操作按钮之间,可以使用任何可用的空间。 自定义导航视图的常见用例可能包括浏览器的自动建议地址栏或其他导航机制,这些机制不能很好地转换为提供的导航模式。
必须设置显示选项 DISPLAY_SHOW_CUSTOM以显示自定义视图。
| 参数(Parameters) | |
|---|---|
resId |
int: Resource ID of a layout to inflate into the ActionBar. |
也可以看看:
void setCustomView (View view, ActionBar.LayoutParams layoutParams)
将操作栏设置为自定义导航模式,为自定义导航提供视图。
自定义导航视图显示在应用程序图标和任何操作按钮之间,可以使用任何可用的空间。 自定义导航视图的常见用例可能包括浏览器的自动建议地址栏或其他导航机制,这些机制不能很好地转换为提供的导航模式。
必须设置显示选项 DISPLAY_SHOW_CUSTOM才能显示自定义视图。
| 参数(Parameters) | |
|---|---|
view |
View: Custom navigation view to place in the ActionBar. |
layoutParams |
ActionBar.LayoutParams: How this custom view should layout in the bar. |
也可以看看:
void setDisplayHomeAsUpEnabled (boolean showHomeAsUp)
设置家庭是否应该显示为“up”的可供选择性。 如果选择“home”返回到您的UI中的单个级别而不是回到顶级或首页,请将其设置为true。
要一次设置多个显示选项,请参阅setDisplayOptions方法。
| 参数(Parameters) | |
|---|---|
showHomeAsUp |
boolean: true to show the user that selecting home will return one level up rather than to the top level of the app. |
void setDisplayOptions (int options,
int mask)
设置选定的显示选项。 只有由掩码指定的选项才会更改。 要一次更改所有显示选项位,请参阅setDisplayOptions(int) 。
例如:setDisplayOptions(0,DISPLAY_SHOW_HOME)将禁用DISPLAY_SHOW_HOME选项。 setDisplayOptions(DISPLAY_SHOW_HOME,DISPLAY_SHOW_HOME | DISPLAY_USE_LOGO)将启用DISPLAY_SHOW_HOME并禁用DISPLAY_USE_LOGO 。
| 参数(Parameters) | |
|---|---|
options |
int: A combination of the bits defined by the DISPLAY_ constants defined in ActionBar. |
mask |
int: A bit mask declaring which display options should be changed. |
void setDisplayOptions (int options)
设置显示选项。 这会一次更改所有显示选项位。 要更改显示选项的有限子集,请参阅setDisplayOptions(int, int) 。
| 参数(Parameters) | |
|---|---|
options |
int: A combination of the bits defined by the DISPLAY_ constants defined in ActionBar. |
void setDisplayShowCustomEnabled (boolean showCustom)
设置是否应显示自定义视图(如果已设置)。
要一次设置多个显示选项,请参阅setDisplayOptions方法。
| 参数(Parameters) | |
|---|---|
showCustom |
boolean: true if the currently set custom view should be displayed, false otherwise. |
void setDisplayShowHomeEnabled (boolean showHome)
设置是否将应用程序主页示功表包含在操作栏中。 首页作为活动图标或徽标呈现。
要一次设置多个显示选项,请参阅setDisplayOptions方法。
| 参数(Parameters) | |
|---|---|
showHome |
boolean: true to show home, false otherwise. |
void setDisplayShowTitleEnabled (boolean showTitle)
设置是否显示活动标题/副标题。
要一次设置多个显示选项,请参阅setDisplayOptions方法。
| 参数(Parameters) | |
|---|---|
showTitle |
boolean: true to display a title/subtitle if present. |
void setDisplayUseLogoEnabled (boolean useLogo)
设置是否显示活动徽标而不是活动图标。 徽标通常是一个更广泛,更详细的图像。
要一次设置多个显示选项,请参阅setDisplayOptions方法。
| 参数(Parameters) | |
|---|---|
useLogo |
boolean: true to use the activity logo, false to use the activity icon. |
void setElevation (float elevation)
以像素为单位设置操作栏的Z轴高程。
操作栏的高程是它从其父表面放置的距离。 较高的值更接近用户。
| 参数(Parameters) | |
|---|---|
elevation |
float: Elevation value in pixels |
void setHideOffset (int offset)
设置操作栏的当前隐藏偏移量。
操作栏的当前隐藏偏移量是操作栏当前以像素为单位滚动离屏的距离。 有效范围为0(完全可见)到操作栏当前测量的height (完全不可见)。
| 参数(Parameters) | |
|---|---|
offset |
int: The action bar's offset toward its fully hidden state in pixels. |
void setHideOnContentScrollEnabled (boolean hideOnContentScroll)
在内容滚动中启用隐藏操作栏。
如果启用,操作栏将nested scrolling child视图的内容一起向外滚动。 操作栏必须位于overlay mode以启用隐藏内容滚动。
当部分滚动屏幕时,操作栏被认为是hidden 。 致电show将导致它返回到全视图。
| 参数(Parameters) | |
|---|---|
hideOnContentScroll |
boolean: true to enable hiding on content scroll. |
void setHomeActionContentDescription (CharSequence description)
设置Home / Up操作的备用描述。
此描述通常用于启用“主页”操作时的辅助功能/屏幕阅读器。 (请参阅setDisplayHomeAsUpEnabled(boolean) )根据DISPLAY_HOME_AS_UP显示选项,此示例为“导航首页”或“导航”。 如果您已使用setHomeAsUpIndicator(int)更改了家中指示灯,以指示更具体的功能(如滑动抽屉),则还应将其设置为准确描述该操作。
将其设置为 null将使用系统默认描述。
| 参数(Parameters) | |
|---|---|
description |
CharSequence: New description for the Home action when enabled |
void setHomeActionContentDescription (int resId)
设置Home / Up操作的备用描述。
此描述通常用于启用“主页”操作时的辅助功能/屏幕阅读器。 (请参阅setDisplayHomeAsUpEnabled(boolean) )根据DISPLAY_HOME_AS_UP显示选项,此示例为“导航首页”或“导航”。 如果您使用setHomeAsUpIndicator(int)更改了家中指示器以指示更具体的功能,例如滑动抽屉,则还应该将其设置为准确描述该操作。
将其设置为 0将使用系统默认描述。
| 参数(Parameters) | |
|---|---|
resId |
int: Resource ID of a string to use as the new description for the Home action when enabled |
void setHomeAsUpIndicator (int resId)
当启用DISPLAY_HOME_AS_UP时,设置另一个可绘制的图标以在图标/徽标/标题旁显示。 如果您使用此模式显示上方导航的替代选择,例如滑动抽屉,则此功能非常有用。
如果您将 0传递给此方法,则将使用主题的默认可绘制。
如果您在Up上执行备用或中间行为,则还应该致电 setHomeActionContentDescription()以提供有关辅助功能支持操作的正确说明。
| 参数(Parameters) | |
|---|---|
resId |
int: Resource ID of a drawable to use for the up indicator, or 0 to use the theme's default |
void setHomeAsUpIndicator (Drawable indicator)
当启用DISPLAY_HOME_AS_UP时,设置一个替代的可绘制图标以在图标/徽标/标题旁显示。 如果您使用此模式显示上方导航的替代选择,例如滑动抽屉,则此功能非常有用。
如果您将 null传递给此方法,则将使用主题的默认drawable。
如果您在Up上执行备用或中间行为,则还应该致电 setHomeActionContentDescription()以提供可访问性支持操作的正确说明。
| 参数(Parameters) | |
|---|---|
indicator |
Drawable: A drawable to use for the up indicator, or null to use the theme's default |
void setHomeButtonEnabled (boolean enabled)
启用或禁用操作栏角落中的“主页”按钮。 (请注意,这是应用程序主页上的动作栏,而不是系统范围的主页按钮。)
对于定位<API 14的软件包,此默认值为true。对于定位API 14或更高版本的软件包,应用程序应该调用此方法以启用与家庭/实用程序功能的交互。
设置 DISPLAY_HOME_AS_UP显示选项将自动启用主页按钮。
| 参数(Parameters) | |
|---|---|
enabled |
boolean: true to enable the home button, false to disable the home button. |
void setIcon (Drawable icon)
将图标设置为显示在操作栏的“主页”部分。 操作栏默认使用由其风格或活动图标指定的图标。 显示选项DISPLAY_USE_LOGO是否控制主页显示图标或徽标。
| 参数(Parameters) | |
|---|---|
icon |
Drawable: Drawable to show as an icon. |
void setIcon (int resId)
将图标设置为显示在操作栏的“主页”部分。 操作栏默认使用由其风格或活动图标指定的图标。 显示选项DISPLAY_USE_LOGO是否控制主页显示图标或徽标。
| 参数(Parameters) | |
|---|---|
resId |
int: Resource ID of a drawable to show as an icon. |
void setListNavigationCallbacks (SpinnerAdapter adapter, ActionBar.OnNavigationListener callback)
此方法已弃用。
内置工具栏操作栏不支持操作栏导航模式。 考虑使用其他common navigation patterns来代替。
为列表导航模式设置适配器和导航回调。 提供的适配器将为扩展列表以及当前选定的项目提供视图。 (这些可能会以不同方式显示。)提供的OnNavigationListener将在用户更改当前列表选择时提醒应用程序。
| 参数(Parameters) | |
|---|---|
adapter |
SpinnerAdapter: An adapter that will provide views both to display the current navigation selection and populate views within the dropdown navigation menu. |
callback |
ActionBar.OnNavigationListener: An OnNavigationListener that will receive events when the user selects a navigation item. |
void setLogo (int resId)
将徽标设置为显示在操作栏的“主页”部分。 操作栏默认使用由其风格或活动徽标指定的徽标。 显示选项DISPLAY_USE_LOGO是否控制主页显示图标或徽标。
| 参数(Parameters) | |
|---|---|
resId |
int: Resource ID of a drawable to show as a logo. |
void setLogo (Drawable logo)
将徽标设置为显示在操作栏的“主页”部分。 操作栏默认使用由其风格或活动徽标指定的徽标。 显示选项DISPLAY_USE_LOGO是否控制主页显示图标或徽标。
| 参数(Parameters) | |
|---|---|
logo |
Drawable: Drawable to show as a logo. |
void setNavigationMode (int mode)
此方法已弃用。
内置工具栏操作栏不支持操作栏导航模式。 考虑改用其他common navigation patterns 。
设置当前的导航模式。
| 参数(Parameters) | |
|---|---|
mode |
int: The new mode to set. |
void setSelectedNavigationItem (int position)
此方法已弃用。
内置工具栏操作栏不支持操作栏导航模式。 考虑改用其他common navigation patterns 。
以列表或标签导航模式设置选定的导航项目。
| 参数(Parameters) | |
|---|---|
position |
int: Position of the item to select. |
void setSplitBackgroundDrawable (Drawable d)
设置ActionBar的分割背景。 这将显示在包含某些设备和配置上的菜单提供的操作按钮的拆分操作栏中。
您可以使用 uiOptions启用拆分操作栏
| 参数(Parameters) | |
|---|---|
d |
Drawable: Background drawable for the split bar |
void setStackedBackgroundDrawable (Drawable d)
设置ActionBar的堆叠背景。 这将出现在某些设备和配置的第二行/堆叠栏中。
| 参数(Parameters) | |
|---|---|
d |
Drawable: Background drawable for the stacked row |
void setSubtitle (CharSequence subtitle)
设置操作栏的副标题。 这仅在设置了DISPLAY_SHOW_TITLE时才会显示。 设置为null以完全禁用字幕。
| 参数(Parameters) | |
|---|---|
subtitle |
CharSequence: Subtitle to set |
void setSubtitle (int resId)
设置操作栏的副标题。 这仅在设置了DISPLAY_SHOW_TITLE时才会显示。
| 参数(Parameters) | |
|---|---|
resId |
int: Resource ID of subtitle string to set |
void setTitle (CharSequence title)
设置操作栏的标题。 这仅在设置了DISPLAY_SHOW_TITLE时才会显示。
| 参数(Parameters) | |
|---|---|
title |
CharSequence: Title to set |
void setTitle (int resId)
设置操作栏的标题。 这仅在设置了DISPLAY_SHOW_TITLE时才会显示。
| 参数(Parameters) | |
|---|---|
resId |
int: Resource ID of title string to set |
void show ()
显示ActionBar,如果它当前不显示。 如果承载ActionBar的窗口不具有功能FEATURE_ACTION_BAR_OVERLAY ,它将调整应用程序内容的大小以适应新的可用空间。
如果您通过 View.SYSTEM_UI_FLAG_FULLSCREEN隐藏了ActionBar,则不应直接调用此函数。