Archive

Posts Tagged ‘bar’

Expand the status notification bar

March 20, 2012 1 comment

This is a really nice trick.

If you’ve ever tried some Launcher like: ADW Launcher, Go Launcher EX….you may pay attention that when you fling down on Home screen, it will scroll down the status notification bar.

Here what it  looks like..in my phone while scrolling down if you can’t imagine what I’m talking about.

Expand Status Bar

Expand Status Bar

About the implementation:

Object service  = getSystemService("statusbar");
Class<?> statusbarManager = Class.forName("android.app.StatusBarManager");
Method expand = statusbarManager.getMethod("expand");
expand.invoke(service);

Also you need to add a required permission, that is: "android.permission.EXPAND_STATUS_BAR"

Happy coding!

Cheers,

Pete Houston

Advertisements

Colorizing the Title Bar

September 20, 2011 2 comments

It’s very interesting if we can do some customizing over title bar on screen, like this:

Colorizing Title Bar

Colorizing Title Bar

Here the tricks:

package pete.android.study;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.ViewParent;
import android.widget.TextView;

public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        // load title bar from Android layout
        TextView titleBar = (TextView)getWindow().findViewById(android.R.id.title);
        if (titleBar != null) {
            // set text color, YELLOW as sample
            titleBar.setTextColor(Color.YELLOW);
            // find parent view
            ViewParent parent = titleBar.getParent();
            if (parent != null && (parent instanceof View)) {
                // set background on parent, BRICK as sample
                View parentView = (View)parent;
                parentView.setBackgroundColor(Color.rgb(0x88, 0x33, 0x33));
            }
        }
    }
}

If you want to do some customization on default Android screen layout by re-construct the framework, then refer to this file: platforms/android-2.3.3/data/res/layout/screen.xml, whereas replace 2.3.3 by your version.

Have fun 😀

 

Cheers,

Pete Houston

Categories: Tricks & Tips Tags: , , ,

Get Window Status Bar and Title Bar Height Size

September 4, 2011 1 comment

Size of Bar

Size of Bar

This is an interesting tip 🙂 to get the height size of status bar and title bar, assuming that they are both on the top of screen.

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        tvContent = (TextView)findViewById(R.id.tvContent);
        tvContent.postDelayed(new Runnable() {

			@Override
			public void run() {
				 String display = String.format("Status Bar Height = %d\nTitle Bar Height = %d", getStatusBarHeight(), getTitleBarHeight());
			     tvContent.setText(display);

			}
		}, 2000);

    }

    public int getStatusBarHeight() {
    	Rect r = new Rect();
    	Window w = getWindow();
    	w.getDecorView().getWindowVisibleDisplayFrame(r);
    	return r.top;
    }

    public int getTitleBarHeight() {
    	int viewTop = getWindow().findViewById(Window.ID_ANDROID_CONTENT).getTop();
    	return (viewTop - getStatusBarHeight());
    }

The reason why getting directly inside onCreate() method doesnot work is because the view is being measured; so it’s better to retrieve the size after finishing measuring. In this case, I attach a handler to the TextView and run after 2 seconds delay. You also can run on a Listener as well.

Cheers,
Pete Houston

Categories: Tricks & Tips Tags: , , , , ,