Android: Adding text from textView to status bar

后端 未结 3 886
轮回少年
轮回少年 2020-12-18 14:20

Is it possible to add the String taken from textView to Status Bar. I want to show text constantly , dynamically updated as textView from apps main activity.



        
相关标签:
3条回答
  • 2020-12-18 14:39

    TextView message = (TextView) findViewById(R.id.textView1); message.setText("This I want to add to status bar");

    ActionBar actionBar = getSupportActionBar(); actionBar.setTittle(message.getText().toString());

    That should fix your problem.

    0 讨论(0)
  • 2020-12-18 14:46

    Yes, you can

    private static void generateNotification(Context context, String message) {
            int icon = R.drawable.ic_status;
            long when = System.currentTimeMillis();
            NotificationManager notificationManager = (NotificationManager) context
                    .getSystemService(Context.NOTIFICATION_SERVICE);
            Notification notification = new Notification(icon, message, when);
            String title = context.getString(R.string.app_name); // Here you can pass the value of your TextView
            Intent notificationIntent = new Intent(context, SplashScreen.class);
            notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
                    | Intent.FLAG_ACTIVITY_SINGLE_TOP);
            PendingIntent intent = PendingIntent.getActivity(context, 0,
                    notificationIntent, 0);
            notification.setLatestEventInfo(context, title, message, intent);
            notification.flags |= Notification.FLAG_AUTO_CANCEL;
            notificationManager.notify(0, notification);
        }
    
    0 讨论(0)
  • 2020-12-18 14:57

    Yes it is possible to show text from textview to status bar, you have to create notification And here is the guide on how to update notification text at runtime.

    0 讨论(0)
提交回复
热议问题