原来以为这Launcher的左边实现一个自定义的内容会很复杂。看完launcher的代码后才发现,原来launcher已经帮我们做好了。
只需要两步
第一步重写下面的方法,设置为true
/** To be overriden by subclasses to hint to Launcher that we have custom content */
protected boolean hasCustomContentToLeft() {
return true;
}
第二步,
重写populateCustomContentContainer方法,在里面调用addToCustomContentPage,把你的View加入即可。
/**
* To be overridden by subclasses to populate the custom content container and call
* {@link #addToCustomContentPage}. This will only be invoked if
* {@link #hasCustomContentToLeft()} is {@code true}.
*/
protected void populateCustomContentContainer() {
if (hasCustomContentToLeft()) {
mLScreen = LScreenFactory.generatorScreen(this);
// CellLayout mieScreen = mWorkspace
// .getScreenWithId(Workspace.CUSTOM_CONTENT_SCREEN_ID);
// mieScreen.addView(mLScreen.getScreenView());
// CR949657 lingjian.he added begin 20150402
}
// PR894160 LScreen 20150112 lingjian.he added end
addToCustomContentPage(mLScreen.getScreenView(), mCustomCallback , "OneTouchStream");
}
我只想说,LAUNCHER的代码写得太牛了