Android statusbar: Add back, home, and menu buttons

Source: Internet
Author: User

Add the home, back, and menu menus to the system status bar on the android interface and complete the corresponding system functions. And the higlight effect is displayed. Modify the height of the status bar and the text size on the status bar.

This requires the android SDK to be modified. I use eclair. The following describes my operations.

1. First, complete the display.

File to be modified

. /Frameworks/base/services/Java/COM/Android/Server/status/statusbarpolicy. java: Add a custom icon in the format of mbatteryicon and other icons. Just specify the image name. In addition, remember to modify./frameworks/base/CORE/RES/values/arrays. xml. the slot of the icon is defined here and the placement order of the icon is determined.

In this way, the icon button you need can be displayed on the system status bar.

 

2. Determine whether touch event has triggered an icon.

File to be modified

./Frameworks/base/services/Java/COM/Android/Server/status/statusbarview. Java

First, in the ontouchevent function, obtain the coordinates of the current event, and then compare whether it is within a certain key range. Because the system has defined the statusbar range, you only need to compare the abscissa here.

Second, this step is also the most critical. How can we obtain the left and right boundary coordinates of a specific icon? The icons displayed on the left of the system status bar are notification, and the system icon is displayed on the right. that is to say, the icon on the left belongs to mnotificationicons, And the icon on the right belongs to mstatusicons. in the file statusbarview. in Java, offset = getviewoffset (mstatusicons) is used to obtain the left abscissa of the leftmost icon of mstatusicons. Use n = mstatusicons. getchildcount () obtains several system icons, including the icons whose visibility is false. use mstatusicons. getchildat (n-I) obtains the icon view from the number I on the right. the getleft () + offset of this view is the left horizontal coordinate of the I-th icon, and the corresponding getright () + offset is the Right horizontal coordinate of the I-th icon. In this example, the Home Key is 2nd icons on the right.

 

3. Define icon response events

The method used here is in statusbarview. Java

./Frameworks/base/services/Java/COM/Android/Server/status/statusbarpolicy. Java sends a broadcast for statusbarpolicy to complete specific event operations. Note that. /frameworks/base/CORE/Java/Android/content/intent. define intent in Java, and add the intent filter action in the statusbarpolicy constructor, that is, filter. addaction (intent. action_backicon_changed ). for example, if you press the back key and the current event is action_up, A keyevent is sent to the system, and the keycode is keyevent. keycode_back. here we borrow. /frameworks/base/cmds/input/src/COM/Android/commands/input. the sendkeyevent function in Java is directly copied. You can modify the parameters as needed. do not modify the process.

It should be noted that when you click statusbar to pull out a notification list, when the list is displayed, the response speed of the three back, menu, and home keys will be very slow, therefore, the system does not respond to the event and hides the three keys. In the ontouchevent () of statusbarview, no response is returned when mservice. mservice. mtracking is true. Mservice is a statusbarservice object. The three keys are also hidden using broadcast, but the intent is sent by statusbarservie. It is displayed when mexpandedvisible = false and hidden when mexpandedvisible = true.

At the same time, we have completed the highlight chart change operation, which is also done by broadcast. The process is the same as that of action_down and action_up.

 

4. Adjust the height of the status bar

If you want to display a large screen size and the statusbar height to be enlarged, the size of the icon above needs to be increased. To ensure consistency, the font of the display time and the date displayed by notification must also be increased. The procedure is as follows:

A. adjust the size of the status bar icon: only the textsize label of status_bar.xml does not seem to work, and it is modified at the same time. /base/services/Java/COM/Android/Server/status/statusbaricon. java T. settextsize (32); the statement is successful. I don't know if it is necessary to modify the value of layout_height under the <com. Android. server. Status. animatedimageview> label of status_bar.xml. I changed it all together.

B. Adjust the Status Bar Height:./base/CORE/RES/values/dimens. xml! I do not know whether to modify the windowtitlesize value of window attributes in./base/CORE/RES/values/themes. xml. I also changed it.

C. Adjust the date font size of notification display and modify the textsize value of <com. Android. server. Status. dateview> of status_bar.xml.

Now, we have finished all the work. Let's take a look at the effect.

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.