Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding title back to Android window when using PhoneGap

I'm building an app using PhoneGap, which calls

getWindow().requestFeature(Window.FEATURE_NO_TITLE);

in the parent onCreate (DroidGap). But, I want to add the title back on so I can use an ActionBar. Is there any flag/way to reset this feature back? If worst comes to worst, I can modify the entire DroidGap class, but would like to still use their version.

And in case it helps anyone to see what DroidGap does in its onCreate, here's the link: https://github.com/phonegap/phonegap-android/blob/master/framework/src/com/phonegap/DroidGap.java

ActionBar code:

super.onCreate(savedInstanceState); 
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.main);
getWindow().requestFeature(Window.FEATURE_ACTION_BAR); super.init();
ActionBar bar = getActionBar(); 
bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); // here NPE is thrown
bar.addTab(bar.newTab().setText("Some Text").setTabListener(new CustomTabListener()));
like image 739
mikesir87 Avatar asked Dec 13 '25 06:12

mikesir87


2 Answers

Phonegap / Cordova version 1.9 added a flag to toggle this feature:

if(!this.getBooleanProperty("showTitle", false))
{
    getWindow().requestFeature(Window.FEATURE_NO_TITLE);
}

Example onCreate method that enables window title:

@Override
public void onCreate(Bundle savedInstanceState) {

    // enable window title for actionbar support
    super.setBooleanProperty("showTitle", true);

    super.onCreate(savedInstanceState);        
}
like image 89
Jan Laussmann Avatar answered Dec 14 '25 20:12

Jan Laussmann


Have you tested FEATURE_CUSTOM_TITLE?

getWindow().requestFeature(Window.FEATURE_CUSTOM_TITLE);
getWindow().setTitle(getResources().getString(R.string.app_name));

or try loading Theme with title bar:

setTheme(android.R.style.choose some of the themes listed or create your own);
like image 32
Nikola Despotoski Avatar answered Dec 14 '25 20:12

Nikola Despotoski



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!