我正在研究ActionBar,并看到了这种抽象方法
public abstract Tab newTab();
但是,仅在ActionBarImpl.java中可以看到newTab的实现。
来自android http://developer.android.com/reference/android/support/v4/view/ViewPager.html
结果表明
final ActionBar bar = getActionBar();
bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
bar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE);
mTabsAdapter = new TabsAdapter(this, mViewPager);
mTabsAdapter.addTab(bar.newTab().setText("Simple"), CountingFragment.class, null);
那么,bar.newTab()实际在哪里实例化?
我看到了相关的文章我应该扩展什么类,AcionBar或ActionBarImpl?但这似乎并不能直接回答我的问题。
该ActionBar
班是一个抽象类,像你已经找到了。它实际上是在ActionBarImp
课堂上实现的。与ActionBar相关的所有内容都将在Activity
类中实例化。getActionBar()
将返回此实现ActionBar
:
/**
* Retrieve a reference to this activity's ActionBar.
*
* @return The Activity's ActionBar, or null if it does not have one.
*/
public ActionBar getActionBar() {
initActionBar();
return mActionBar;
}
/**
* Creates a new ActionBar, locates the inflated ActionBarView,
* initializes the ActionBar with the view, and sets mActionBar.
*/
private void initActionBar() {
[...]
mActionBar = new ActionBarImpl(this);
[...]
}
来源。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句