Modify the status bar icon (custom status bar)

Source: Internet
Author: User

For system customization, You need to modify the status bar. If you want to brush the machine, there are a lot of online materials, but there are not many materials to modify the source code. In 2.2, the source code is in frameworks/base/services/Java/COM/Android/Server/status/statusbarpolicy. java and frameworks/base/services/Java/COM/Android/Server/status/statusbarservice. in Java, in 2.3, the source code is in systemui in frameworks/base/package.

In statusbarpolicy, the code for adding an icon is as follows (Row 3 ):

 public StatusBarPolicy(Context context) {        mContext = context;        mService = (StatusBarManager)context.getSystemService(Context.STATUS_BAR_SERVICE);        mSignalStrength = new SignalStrength();        mBatteryStats = BatteryStatsService.getService();        // storage        mStorageManager = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE);        mStorageManager.registerListener(                new com.android.systemui.usb.StorageNotification(context));        // battery        mService.setIcon("battery", com.android.internal.R.drawable.stat_sys_battery_unknown, 0);        // phone_signal        mPhone = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);        mPhoneSignalIconId = R.drawable.stat_sys_signal_null;        mService.setIcon("phone_signal", mPhoneSignalIconId, 0);        mService.setIconVisibility("phone_signal",false);        // register for phone state notifications.        ((TelephonyManager)mContext.getSystemService(Context.TELEPHONY_SERVICE))                .listen(mPhoneStateListener,                          PhoneStateListener.LISTEN_SERVICE_STATE                        | PhoneStateListener.LISTEN_SIGNAL_STRENGTHS                        | PhoneStateListener.LISTEN_CALL_STATE                        | PhoneStateListener.LISTEN_DATA_CONNECTION_STATE                        | PhoneStateListener.LISTEN_DATA_ACTIVITY);        // data_connection        mService.setIcon("data_connection", R.drawable.stat_sys_data_connected_g, 0);        mService.setIconVisibility("data_connection", false);        // wifi        mService.setIcon("wifi", sWifiSignalImages[0][0], 0);        mService.setIconVisibility("wifi", false);        // wifi will get updated by the sticky intents        // TTY status        mService.setIcon("tty",  R.drawable.stat_sys_tty_mode, 0);        mService.setIconVisibility("tty", false);        // Cdma Roaming Indicator, ERI        mService.setIcon("cdma_eri", R.drawable.stat_sys_roaming_cdma_0, 0);        mService.setIconVisibility("cdma_eri", false);        // bluetooth status        mService.setIcon("bluetooth", R.drawable.stat_sys_data_bluetooth, 0);        BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();        if (adapter != null) {            mBluetoothEnabled = adapter.isEnabled();        } else {            mBluetoothEnabled = false;        }        mBluetoothA2dpConnected = false;        mBluetoothHeadsetState = BluetoothHeadset.STATE_DISCONNECTED;        mBluetoothPbapState = BluetoothPbap.STATE_DISCONNECTED;        mService.setIconVisibility("bluetooth", mBluetoothEnabled);        // Gps status        mService.setIcon("gps", R.drawable.stat_sys_gps_acquiring_anim, 0);        mService.setIconVisibility("gps", false);        // Alarm clock        mService.setIcon("alarm_clock", R.drawable.stat_notify_alarm, 0);        mService.setIconVisibility("alarm_clock", false);        // Sync state        mService.setIcon("sync_active", com.android.internal.R.drawable.stat_notify_sync_anim0, 0);        mService.setIcon("sync_failing", com.android.internal.R.drawable.stat_notify_sync_error, 0);        mService.setIconVisibility("sync_active", false);        mService.setIconVisibility("sync_failing", false);        // volume        mService.setIcon("volume", R.drawable.stat_sys_ringer_silent, 0);        mService.setIconVisibility("volume", false);        updateVolume();        IntentFilter filter = new IntentFilter();        // Register for Intent broadcasts for...        filter.addAction(Intent.ACTION_BATTERY_CHANGED);        filter.addAction(Intent.ACTION_BATTERY_LOW);        filter.addAction(Intent.ACTION_BATTERY_OKAY);        filter.addAction(Intent.ACTION_POWER_CONNECTED);        filter.addAction(Intent.ACTION_ALARM_CHANGED);        filter.addAction(Intent.ACTION_SYNC_STATE_CHANGED);        filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION);        filter.addAction(AudioManager.VIBRATE_SETTING_CHANGED_ACTION);        filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);        filter.addAction(BluetoothHeadset.ACTION_STATE_CHANGED);        filter.addAction(BluetoothA2dp.ACTION_SINK_STATE_CHANGED);        filter.addAction(BluetoothPbap.PBAP_STATE_CHANGED_ACTION);        filter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);        filter.addAction(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION);        filter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);        filter.addAction(WifiManager.RSSI_CHANGED_ACTION);        filter.addAction(LocationManager.GPS_ENABLED_CHANGE_ACTION);        filter.addAction(LocationManager.GPS_FIX_CHANGE_ACTION);        filter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);        filter.addAction(TtyIntent.TTY_ENABLED_CHANGE_ACTION);        filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);        filter.addAction(ConnectivityManager.INET_CONDITION_ACTION);        mContext.registerReceiver(mIntentReceiver, filter, null, mHandler);        // load config to determine if to distinguish Hspa data icon        try {            mHspaDataDistinguishable = mContext.getResources().getBoolean(                    R.bool.config_hspa_data_distinguishable);        } catch (Exception e) {            mHspaDataDistinguishable = false;        }    }

The following describes how to get statusbarmanager:

Private Final statusbarmanager mservice;

Mservice = (statusbarmanager) context. getsystemservice (context. status_bar_service); The following is the get icon: Get and process it later // phone_signal mphone = (telephonymanager) context. getsystemservice (context. telephony_service); mphonesignaliconid = R. drawable. stat_sys_signal_null; mservice. seticon ("phone_signal", mphonesignaliconid, 0); mservice. seticonvisibility ("phone_signal", false );

Here, I have hidden this signal icon. So when you compile the source code, generate your own SDK, and create a new simulator, you will find that the signal icon is gone, if you want to change the layout, or change the icon, find the corresponding file in res and write the file today. Continue with the remaining information.

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.