我已经给你答案了。你可以在Launcher2
and Launcher3
来自 (AOSP) 的包。果冻豆正在使用Launcher2
或许。我个人建议你去Launcher3
,它有内置的方法来做到这一点。
启动器3:
创建一个类来扩展com.android.launcher3.Launcher
类并重写必要的方法,如下所示:
public class MyLauncher extends Launcher {
@Override
protected boolean hasCustomContentToLeft() {
return true;
}
@Override
protected void addCustomContentToLeft() {
View customView = getLayoutInflater().inflate(R.layout.custom, null);
CustomContentCallbacks callbacks = new CustomContentCallbacks() {
@Override
public void onShow() {}
@Override
public void onScrollProgressChanged(float progress) {}
@Override
public void onHide() {}
};
addToCustomContentPage(customView, callbacks, "custom view");
}
}
Here R.layout.custom
是您想要的自定义视图。
然后在清单文件中更改启动器活动类Launcher
to MyLauncher
。就是这样。
启动器2:
in Workspace.java
创建以下方法:
public void addCustomView(View child){
CellLayout layout = (CellLayout) getChildAt(0);
layout.addView(child);
}
then in Launcher.java
,找到以下行:
mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
然后将以下代码粘贴到该行之后的某个位置:
View child = LayoutInflater.from(this).inflate(R.layout.custom, null);
mWorkspace.addCustomView(child);