Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set text on status bar?

Tags:

android

How to set text on status bar (line that placed Battery life, time ..etc) ?

Thanks in advance.

like image 281
AndroiDBeginner Avatar asked Jan 16 '10 07:01

AndroiDBeginner


People also ask

How do I make my status bar text black?

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.

How can I change my status bar style in Android?

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.

How can I change my status bar position?

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.


1 Answers

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
like image 144
Dave Webb Avatar answered Oct 10 '22 00:10

Dave Webb