Java Android:将文本从textView添加到状态栏
是否可以将文本视图中的字符串添加到状态栏中。我想不断显示文本,动态更新为应用程序主活动中的文本视图Java Android:将文本从textView添加到状态栏,java,android,textview,statusbar,Java,Android,Textview,Statusbar,是否可以将文本视图中的字符串添加到状态栏中。我想不断显示文本,动态更新为应用程序主活动中的文本视图 TextView message = (TextView) findViewById(R.id.textView1); message.setText("This I want to add to status bar"); 是的,你可以 private static void generateNotification(Context context, String message) {
TextView message = (TextView) findViewById(R.id.textView1);
message.setText("This I want to add to status bar");
是的,你可以
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);
}
是的,可以将文本从textview显示到状态栏,您必须创建,下面是关于如何在运行时更新通知文本的说明。textview消息=(textview)findViewById(R.id.textView1); message.setText(“我想将其添加到状态栏”) ActionBar ActionBar=getSupportActionBar(); actionBar.setTitle(message.getText().toString())
这应该可以解决你的问题。我是说通知栏,它总是在屏幕的顶部,所以你想使用通知?是的,但我只需要在时钟旁边显示变量。你找到如何向通知栏添加文本了吗?我试过这种方法,一切都很好,但我还想在图标旁边添加变量的值,使用上面的方法,获取textview的字符串并将其传递给上面的方法。是的,但我想一直显示它,而不是一秒钟。它被称为股票代码文本或类似的东西