How to add custom view in android's JellyBean Launcher How to add custom view in android's JellyBean Launcher android android

How to add custom view in android's JellyBean Launcher


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.

Launcher3:

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.

Launcher2:

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 I remember correctly you just need to implement a standard activity which displays a home launcher. In your Manifest.xml you just need to define it like this:

<activity android:name=".YourLauncher" android:label="@string/launcher_name">    <intent-filter>        <action android:name="android.intent.action.MAIN" />        <category android:name="android.intent.category.LAUNCHER" />    </intent-filter></activity>


you can simply add view in default lanucher use code

wm = (WindowManager) getSystemService("window");params = new LayoutParams();params.type = LayoutParams.TYPE_PHONE;    params.format = PixelFormat.RGBA_8888;    params.flags = LayoutParams.FLAG_NOT_TOUCH_MODAL            | LayoutParams.FLAG_NOT_FOCUSABLE;    params.x = 100;    params.y = 100;    params.height = WindowManager.LayoutParams.WRAP_CONTENT;    params.width = WindowManager.LayoutParams.WRAP_CONTENT;    params.gravity = Gravity.LEFT | Gravity.TOP;wm.addView(view, params);

when you want to remove it just

wm.removeView(v);

you also need permission

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />