How to display countdown timer on status bar in android, like time display?
Asked Answered
E

2

14

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

Erose answered 7/9, 2016 at 18:41 Comment(5)
have you tried the setTicker method in the NotificationCompat.Builder class?Rousing
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 userErose
check out @Shazeel Afzal's answer here. Might be along the lines of what you are looking forRousing
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 folderDionnadionne
I think @uguboz is correctTenancy
C
-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();
                }
            });
        }
    } 
Coaming answered 13/10, 2016 at 19:10 Comment(0)
K
-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

Kedgeree answered 16/12, 2016 at 13:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.