1
votes

Suppose I have an android app with android:theme="@android:style/Theme.NoTitleBar" applied to the application element in the manifest.

Is it possible, for a specific activity, to deviate from this application-wide theme and declaratively (i.e. through the manifest) get a title bar for that activity?

Thanks.

2
Did you try to define new theme for that particular activity? developer.android.com/guide/topics/manifest/… ?ozbek
That could be one approach, I guess - to avoid cruft, I just hoped to be able to get back the titlebar without referring to any specific themes, just as the reverse, removing the titlebar, can be achieved this way.Cumbayah
Ah, I see. Maybe you can use FEATURE_CUSTOM_TITLE (I did not try it myself).ozbek

2 Answers

1
votes

Use setTheme(..) before calling setContentView(...)and super.oncreate() of your specific Activity

@Override
    protected void onCreate(Bundle savedInstanceState) {
        //set Theme here
        setTheme(android.R.style.Theme_DeviceDefault_Light);

        super.onCreate(savedInstanceState);      
        setContentView(R.layout.activity_main);

                .....
}
1
votes

The non-declarative solution proposed by @arun-c-thomas put me on the right path:

Applying @android:style/Theme.DeviceDefault reverts the no-titlebar theme. It is not ideal in that it applies a full theme that would also revert other customizations that might have been in place, but in my case this is not an issue.