Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android: adding button to the title of the app?

Tags:

android

layout

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

like image 897
Yang Avatar asked Apr 02 '10 23:04

Yang


2 Answers

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).

like image 80
CommonsWare Avatar answered Nov 03 '22 13:11

CommonsWare


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);
    }
}
like image 41
Vishwanath Avatar answered Nov 03 '22 12:11

Vishwanath