13

I am making an app which allows the user to pick a date and time. Once the date and time are reached,it will display an animation on the screen. Before its time, it will just show countdown time (like xxx:xx:xx) on screen. I achieved this using a textview which changes every second. How can I display this text on status bar, like time is displayed

I have tried using Notification constructor like in some post I found here but they are depricated and wont work anymore. I tried with NotificationCompat.Builder but it doesnt really have a way to set text which could be displayed on status bar.

Anyone knows any work arpund solution for it, please give me an answer. I just need to display a text on status bar insted of icon

Vidya Sagar
  • 170
  • 1
  • 15
  • have you tried the setTicker method in the NotificationCompat.Builder class? – BiGGZ Sep 29 '16 at 21:12
  • I have tried. The problem is that , as my notification text updates every second, setTicker will display it on notification bar every second with an animation(come from below) which will be very annoying for the user – Vidya Sagar Sep 29 '16 at 22:26
  • check out @Shazeel Afzal's answer [here](http://stackoverflow.com/questions/15437786/android-show-activity-title-status-bar-at-the-top-after-it-is-hidden). Might be along the lines of what you are looking for – BiGGZ Sep 29 '16 at 23:00
  • 2
    create a notification and use setSmallIcon(resId, level). update level with counter. Of course resId must be level list drawable and you must have all the numbers as images in the drawable folder – ugur Oct 06 '16 at 17:39
  • I think @uguboz is correct – behelit Jun 01 '18 at 05:00

2 Answers2

-2

You can set CustomView on the ActionBar by passing a layout file or View. Here is a sample code.

protected void setCustomActionBarTitle(String title) {
        ActionBar actionBar = getActionBar();
        if (actionBar != null) {
            actionBar.setDisplayHomeAsUpEnabled(true);
            actionBar.setDisplayShowCustomEnabled(true);
            actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
            actionBar.setCustomView(R.layout.layout_action_bar_title);
            TextView titleView = (TextView) actionBar.getCustomView().findViewById(R.id.action_bar_title);
            titleView.setText(title);
            ImageView imageView = (ImageView) actionBar.getCustomView().findViewById(R.id.up_icon);
            imageView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    onBackPressed();
                }
            });
        }
    } 
SanthoshN
  • 552
  • 2
  • 13
-2

Add this in your activity_main xml file

<android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:minHeight="@dimen/header_size"
            android:background="?attr/colorPrimary"
            android:layout_gravity="center"
            android:gravity="center">
            <TextView
                android:id="@+id/title"
                android:textColor="@color/title"
                android:gravity="center"
                android:background="@color/white"
                android:layout_width="match_parent"
                android:layout_height="@dimen/header_size"
                android:textSize="@dimen/header_text_size"
                android:textStyle="bold"
                android:text=""/>

        </android.support.v7.widget.Toolbar>

And in your activity add these lines

    actionbar = getSupportActionBar();
    actionbar.setHomeAsUpIndicator(R.drawable.ic_back);
    actionbar.setDisplayHomeAsUpEnabled(true);
    title = (TextView) findViewById(R.id.title);

Now you can set the countdown timer in this textview, also align the TextView as required