I am working on making custom launcher in android. I have referred the code of android's Jellybean launcher. now I want to make some modification in this launcher.
What I want : As we know there are default five work-space screens and I want to add custom view in any one of the workspace screen. My xml file should be inflated in any one of the screen.
I have tried many ways to do it but as the default launcher code is very complex still having no luck to finding out way for it.
There is already app named SOHO in Playstore doing exactly what I want. I have add the screenshot for referencing what i want.
Please help me if anyone of you having any idea to do it.
I've the answer for you. You can do it both in Launcher2
and Launcher3
package from (AOSP). Jellybean is using Launcher2
may be. I personally suggest you to go with Launcher3
, it has buit-in way to do so.
create a class that extends the com.android.launcher3.Launcher
class and override the necessary methods like so:
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
is the custom view that you wanted. Then in the manifest file change the launcher activity class from Launcher
to MyLauncher
. And that's it.
in Workspace.java
create the following method:
public void addCustomView(View child){ CellLayout layout = (CellLayout) getChildAt(0); layout.addView(child); }
then in Launcher.java
, find the following line:
mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
then paste the following code somewhere after that line:
View child = LayoutInflater.from(this).inflate(R.layout.custom, null); mWorkspace.addCustomView(child);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With