Android statusbar modification (1) Add the home back menu key

Source: Internet
Author: User

Because the status bar is completely changed, we recommend that you add a few PNG images first.

Frameworks/base/CORE/RES/drawable
. It is best to make a background image with statusbar_background.png replaced

In addition, I added several icons, including the normal and pressed status of home menu and back.

These images are:
Frameworks \ base \ core \ res \ drawable \ ic_menu_back_pressed.png
Frameworks \ base \ core \ res \ drawable \ ic_menu_home_pressed.png
Frameworks \ base \ core \ res \ drawable \ ic_menu_more_pressed.png
Frameworks \ base \ core \ res \ drawable \ ic_volume_down_pressed.png
Frameworks \ base \ core \ res \ drawable \ ic_volume_up_pressed.png
Frameworks \ base \ core \ res \ drawable \ ic_menu_back.png
Frameworks \ base \ core \ res \ drawable \ ic_menu_home.png
Frameworks \ base \ core \ res \ drawable \ ic_menu_more.png
Frameworks \ base \ core \ res \ drawable \ ic_volume_down.png
Frameworks \ base \ core \ res \ drawable \ ic_volume_up.png

The modification steps are as follows:

1. Modify the XML interface
1. Create button
Frameworks \ base \ core \ res \ drawable \ btn_sbicon_back.xml
Frameworks \ base \ core \ res \ drawable \ btn_sbicon_home.xml
Frameworks \ base \ core \ res \ drawable \ btn_sbicon_menu.xml
Frameworks \ base \ core \ res \ drawable \ btn_sbicon_vol_down.xml
Frameworks \ base \ core \ res \ drawable \ btn_sbicon_vol_up.xml
The base structure is as follows:
<? XML version = "1.0" encoding = "UTF-8"?>
<Selector xmlns: Android = "http://schemas.android.com/apk/res/android">
<Item Android: state_pressed = "true" Android: drawable = "@ drawable/ic_menu_back_pressed"/>
<Item Android: state_pressed = "false" Android: drawable = "@ drawable/ic_menu_back"/>
</Selector>

2. Add an icon
Change the overall status bar by using the following methods:
Modify the layerout file of the status bar:
Frameworks/base/CORE/RES/layout/status_bar.xml
Add an image view in the original linearlayout.

<? XML version = "1.0" encoding = "UTF-8"?>
<Com. Android. server. Status. statusbarview xmlns: Android = "http://schemas.android.com/apk/res/android"
Android: Background = "@ drawable/statusbar_background"
Android: Orientation = "vertical"
Android: focusable = "true"
Android: descendantfocusability = "afterdescendants"
>
<Linearlayout Android: Id = "@ + ID/keys"
Android: layout_width = "wrap_content"
Android: layout_height = "fill_parent"
Android: Orientation = "horizontal">
<Imageview Android: Id = "@ + ID/status_home"
Android: layout_width = "40dip"
Android: layout_height = "40dip"
Android: clickable = "true"
Android: layout_gravity = "TOP"
Android: paddingtop = "1dip"
Android: paddingright = "1dip"
Android: paddingleft = "1dip"
Android: src = "@ drawable/btn_sbicon_home"/>
<Imageview Android: Id = "@ + ID/status_back"
Android: layout_width = "40dip"
Android: layout_height = "40dip"
Android: clickable = "true"
Android: layout_gravity = "TOP"
Android: paddingtop = "1dip"
Android: paddingright = "1dip"
Android: paddingleft = "1dip"
Android: src = "@ drawable/btn_sbicon_back"/>
<Imageview Android: Id = "@ + ID/status_menu"
Android: layout_width = "40dip"
Android: layout_height = "40dip"
Android: clickable = "true"
Android: layout_gravity = "TOP"
Android: paddingtop = "1dip"
Android: paddingright = "1dip"
Android: paddingleft = "1dip"
Android: src = "@ drawable/btn_sbicon_menu"/>
<Imageview Android: Id = "@ + ID/status_vol_down"
Android: layout_width = "40dip"
Android: layout_height = "40dip"
Android: clickable = "true"
Android: layout_gravity = "TOP"
Android: paddingtop = "1dip"
Android: paddingright = "1dip"
Android: paddingleft = "1dip"
Android: src = "@ drawable/btn_sbicon_vol_down"/>
<Imageview Android: Id = "@ + ID/status_vol_up"
Android: layout_width = "40dip"
Android: layout_height = "40dip"
Android: clickable = "true"
Android: layout_gravity = "TOP"
Android: paddingtop = "1dip"
Android: paddingright = "1dip"
Android: paddingleft = "1dip"
Android: src = "@ drawable/btn_sbicon_vol_up"/>
</Linearlayout>
......
</COM. Android. server. Status. statusbarview>
The advantage of doing so is simplicity. At the same time, ensure that the home, menu, and Back buttons are not subject to their original constraints. In this way, the buttons are displayed on the status bar.
You can modify the values of paddingright, paddingleft, and paddingtop to achieve the optimal visual effect.

3. Modify the height of the status bar.
Now that you want to add a few buttons on the status bar, you certainly want to use the touch operation. The height of the status bar that comes with Android is too small and does not apply. For a 7-inch screen, the height of 50 pixels should be almost the same.
It is easy to modify the height. Modify the status_bar_height attribute of frameworks/base/CORE/RES/values/dimens. xml.
<! -- Height of the status bar -->
<Dimen name = "status_bar_height"> 50dip </dimen>

You can also change the Icon size of the status bar, for example, frameworks \ base \ core \ res \ Layout \ status_bar_icon.xml.
<Framelayout xmlns: Android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "25dp"
Android: layout_height = "25dp">

Of course, if you change the title height, you can modify the windowtitlesize value of window attributes in frameworks/base/CORE/RES/values/themes. xml.

Compile and run it:

~ /Donut $ source./env. Sh
~ /Donut $ make-J8
~ /Donut $ emulator-skin wvga800
~ /Donut $ source./env. Sh
~ /Donut $ make-J8
~ /Donut $ emulator-skin wvga800

Check whether the status bar has changed?

2. Add a simulated button for the button
Modify frameworks \ base \ Services \ Java \ com \ Android \ Server \ status \ statusbarview. Java

1. Add a reference to each image button,
Android. widget. linearlayout keyslayout;
Android. widget. imageview btnhome;
Android. widget. imageview btnback;
Android. widget. imageview btnmenu;
Android. widget. imageview btnvolup;
Android. widget. imageview btnvoldown;

2. Modify the onfinishinflate () function. The image IDs are defined in the status_bar.xml File above.
@ Override
Protected void onfinishinflate (){
......
/* Begin: added by tigerpan */
Keyslayout = (Android. widget. linearlayout) findviewbyid (R. Id. Keys );
Btnhome = (Android. widget. imageview) findviewbyid (R. Id. status_home );
Btnback = (Android. widget. imageview) findviewbyid (R. Id. status_back );
Btnmenu = (Android. widget. imageview) findviewbyid (R. Id. status_menu );
Btnvolup = (Android. widget. imageview) findviewbyid (R. Id. status_vol_up );
Btnvoldown = (Android. widget. imageview) findviewbyid (R. Id. status_vol_down );
Btnhome. setonclicklistener (mkeyslistener );
Btnback. setonclicklistener (mkeyslistener );
Btnmenu. setonclicklistener (mkeyslistener );
Btnvolup. setonclicklistener (mkeyslistener );
Btnvoldown. setonclicklistener (mkeyslistener );
/* End: added by tigerpan */
}

3. Add the event listening listener for each button
Android. View. View. onclicklistener mkeyslistener = new Android. View. View. onclicklistener (){
Public void onclick (view v ){
Switch (V. GETID ()){
Case R. Id. status_home:
Mkeyshandler. sendemptymessage (key_home );
Break;
Case R. Id. status_back:
Mkeyshandler. sendemptymessage (key_back );
Break;
Case R. Id. status_menu:
Mkeyshandler. sendemptymessage (key_menu );
Break;
Case R. Id. status_vol_up:
Mkeyshandler. sendemptymessage (key_vol_up );
Break;
Case R. Id. status_vol_down:
Mkeyshandler. sendemptymessage (key_vol_down );
Break;
Default:
Break;
}
}};

4. Add a simulated button
/* Begin: added by tigerpan 20100831 */
Private Static final int key_home = 1000;
Private Static final int key_back= 1001;
Private Static final int key_menu = 1002;
Private Static final int key_vol_up = 1003;
Private Static final int key_vol_down = 1004;
Private handler mkeyshandler = new handler (){
Public void handlemessage (Message MSG ){
Switch (msg. What ){
Case key_home:
SendKey (keyevent. keycode_home );
Break;
Case key_back:
SendKey (keyevent. keycode_back );
Break;
Case key_menu:
SendKey (keyevent. keycode_menu );
Break;
Case key_vol_up:
(Android. Media. audiomanager) mcontext. getsystemservice (context. audio_service ))
. Adjustvolume (Android. Media. audiomanager. adjust_raise, Android. Media. audiomanager. stream_music );
Break;
Case key_vol_down:
(Android. Media. audiomanager) mcontext. getsystemservice (context. audio_service ))
. Adjustvolume (Android. Media. audiomanager. adjust_lower, Android. Media. audiomanager. stream_music );
Break;
Default:
Break;
}
}

Private void sendKey (INT keycode ){
Long Now = systemclock. uptimemillis ();
Long n = system. currenttimemillis ();
Log. D ("tiger", "intent. action_soft _" + keycode + "_ pressed 0 =" + n );
Try {
Keyevent down = new keyevent (now, now, keyevent. action_down, keycode, 0 );
Keyevent up = new keyevent (now, now, keyevent. action_up, keycode, 0 );
Log. D ("tiger", "intent. action_soft _" + keycode + "_ pressed 1 =" + (system. currenttimemillis ()/*-N */));
Iwindowmanager WM = iwindowmanager. stub. asinterface (servicemanager. getservice ("window "));
Log. D ("tiger", "intent. action_soft _" + keycode + "_ pressed 2 =" + (system. currenttimemillis ()/*-N */));
WM. injectkeyevent (down, false );
Log. D ("tiger", "intent. action_soft _" + keycode + "_ pressed 3 =" + (system. currenttimemillis ()/*-N */));
WM. injectkeyevent (up, false );
Log. D ("tiger", "intent. action_soft _" + keycode + "_ pressed 4 =" + (system. currenttimemillis ()/*-N */));
} Catch (RemoteException e ){
Log. I ("input", "deadojbectexception ");
}
}
};
/* End: added by tigerpan 20100831 */

5. avoid triggering the drop-down Notification View when you press these buttons, affecting performance.
Modify the onintercepttouchevent (motionevent event) Function
@ Override
Public Boolean onintercepttouchevent (motionevent event ){
/* Begin: Modified by tigerpan */
If (keyslayout. getright () <event. getx ())
Return mservice. intercepttouchevent (event )? True: Super. onintercepttouchevent (event );
/* Int parentleft = mstatusicons. getleft ();
Android. util. log. I ("tiger ","..... "+ (event. getx () <(parentleft + iconvoldown. getleft () | event. getx ()> (parentleft + iconhome. getright ())));
If (event. getx () <(parentleft + iconvoldown. getleft () | event. getx ()> (parentleft + iconhome. getright ()))
Return mservice. intercepttouchevent (event )? True: Super. onintercepttouchevent (event );
*/
Return false;
/* End: Modified by tigerpan */
}

In this way, it is basically done.

Compile

~ /Donut $ source./env. Sh
~ /Donut $ make Update-API
~ /Donut $ make-J8
~ /Donut $ emulator-skin wvga800
~ /Donut $ source./env. Sh
~ /Donut $ make Update-API
~ /Donut $ make-J8
~ /Donut $ emulator-skin wvga800

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.