tags:

views:

552

answers:

6

Is it possible to add a button to the right corner of the app title?

e.g., adding a "refresh" button to the title of "Feed: my feeds"?

http://www.android.com/market/apps/feedr-lg-01.jpg alt text

+8  A: 

The simplest way to do that, IMHO, is to get rid of the standard title bar (android:theme="@android:style/Theme.NoTitleBar" in the <activity> element in the manifest) and put your own "title bar" at the top of the activity.

Note, though, that the "button in the title bar" style is more iPhone-ish. Android would typically have that in the option menu, so the UI is less cluttered (at the cost of two taps to do the refresh).

CommonsWare
Interestingly, Android are now advocating the inclusion of a consistent titlebar-with-buttons for oft-repeated actions. See, for example, the Google I/O 2010 app and the Twitter UI design patterns blog post: http://android-developers.blogspot.com/2010/05/twitter-for-android-closer-look-at.html
Christopher
+1  A: 

I think a better approach would be to simply refresh the view if it is active by using a Handler. If your pulling content when the activity is resumed then any time you leave and come back to the view it will refresh. If you are expecting users to sit at the top level of the view and need to update the information then you can handle this with a delayed handler which will call your resume method and periodically refresh the view thus negating the need for a button.

Here is a link to the documentation for the handler class. I would start by looking into the basic use of handler. Then test the sendMessageDelayed method so that at the end of every call you restart the handler. Also be sure to only create a new handler if your activity is the top activity and don't bother refreshing the ui if it is not. Adding a simple isActive flag to on pause and on resume is a decent way to check for this.

Dave.B
You assume unlimited data plans. Not everybody has unlimited data plans. Others pay by the megabyte. Automatically refreshing as an option is cool; automatically refreshing as the *only option* is not cool.
CommonsWare
+1  A: 

Why don't you try this

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final boolean customTitle= requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);

    setContentView(R.layout.main);

    if ( customTitle ) {
        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, Set your layout for title here and mention your button in this layout);
    }

    final TextView myTitleText = (TextView) findViewById(R.id.myTitle);
    if ( myTitleText != null ) {
        myTitleText.setText("NEW TITLE");
        myTitleText.setBackgroundColor(Color.BLUE);
    }
}
Vishwanath
+2  A: 

yep this solveed an issue i had... trimmed version is below...

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);

    setContentView(R.layout.main);
    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, Set your layout for title here and mention your button in this layout);

   final TextView myTitleText = (TextView) findViewById(R.id.myTitle);
    if ( myTitleText != null ) {
        /*  your code here */
    }
}
+1  A: 

@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);

final boolean customTitle= requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);

setContentView(R.layout.main);

if ( customTitle ) {
    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, Set your layout for title here and mention your button in this layout);
}

final TextView myTitleText = (TextView) findViewById(R.id.myTitle);
if ( myTitleText != null ) {
    myTitleText.setText("NEW TITLE");
    myTitleText.setBackgroundColor(Color.BLUE);
}

}

This snippet worked for me.. thanks...

dev_in
A: 

if i do so, with final boolean customTitle= requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); and the if-clause i get a NullPointerException. for customTitle. Any ideas?

-rob

rob