How to set text on status bar (line that placed Battery life, time ..etc) ?
Thanks in advance.
Step 1: After opening the android studio and creating a new project with an empty activity. Step 2: Navigate to res/values/colors. xml, and add a color that you want to change for the status bar. Step 3: In your MainActivity, add this code in your onCreate method.
To customize it, first pull down the slider bar from the top of the screen. Next, tap on the three vertical dots in the top right corner. Now click on Status bar. You're in.
2.3. On the Accessibility settings screen, scroll down to “Services section” and tap on Material Status Bar. 2.4. On the next screen, turn ON the Permissions for Material Status Bar by moving the toggle to ON position.
You need to use a Status Bar Notification.
//Create the Notification
Notification notification = new Notification(
android.R.drawable.stat_sys_warning, //Icon to use
"Hello World!", //Text
System.currentTimeMillis() //When to display - i.e. now
);
//Create a PendingIntent to do something when the user clicks on the Notification
//Normally this would be something in your own app
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://www.stackoverflow.com"));
PendingIntent pi = PendingIntent.getActivity(this, 0, intent, 0);
//Add the detail to the Notification
notification.setLatestEventInfo(
getApplicationContext(),
"Stack Overflow", //Title of detail view
"This will launch Stack Overflow", //Text on detail view
pi
);
//Display the Notification
NotificationManager nm = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(ID_HELLO_WORLD, notification); //ID_HELLO_WORLD is a int ID
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With