2013-10-26 3 views
2

textView에서 가져온 String을 상태 표시 줄에 추가 할 수 있습니까? 텍스트를 끊임없이 보여주고 싶습니다. 앱 주요 활동에서 textView로 동적으로 업데이트됩니다.Android : textView에서 상태 표시 줄에 텍스트 추가

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

당신은 작업 표시 줄을 의미합니까? – Raghunandan

+0

나는 항상 화면 상단에있는 알림 표시 줄을 의미합니다. –

+0

알림을 사용 하시겠습니까? –

답변

2

예, 당신은

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

위의 메서드를 사용하여 textview의 String을 가져 와서 위의 메서드로 전달합니다. –

+0

네,하지만 모든 시간을 표시하고 싶습니다. 1 초가 아닙니다. 그 시세 문자 또는 이와 비슷한 전화 –

0

예는 상태 표시 줄에 텍스트 뷰에서 텍스트를 표시 할 수 있습니다, 당신은 notification을 만들 필요가 그리고 여기 런타임에 알림 텍스트를 업데이트하는 방법에 guide입니다 수 있습니다.

1

TextView message = (TextView) findViewById (R.id.textView1); message.setText ("상태 막대에 추가 할 항목");

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

이렇게하면 문제가 해결됩니다.

관련 문제