使用PhoneGap的时候添加标题回的Andr​​oid窗口 [英] Adding title back to Android window when using PhoneGap

查看:119
本文介绍了使用PhoneGap的时候添加标题回的Andr​​oid窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立使用PhoneGap的,这就要求

应用程序

  getWindow()requestFeature(Window.FEATURE_NO_TITLE)。

在父的onCreate(DroidGap)。但是,我想补充的标题后面,所以我可以使用一个动作条。有没有什么标志/方法来重设此功能了?如果出现最坏的情况,我可以修改整个DroidGap类,但希望仍然使用自己的版本。

和的情况下,它可以帮助任何人看到什么DroidGap确实在它的onCreate,这里的链接:<一个href=\"https://github.com/phonegap/phonegap-android/blob/master/framework/src/com/phonegap/DroidGap.java\" rel=\"nofollow\">https://github.com/phonegap/phonegap-android/blob/master/framework/src/com/phonegap/DroidGap.java

动作条code:

  super.onCreate(savedInstanceState);
。getWindow()setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.main);
。getWindow()requestFeature(Window.FEATURE_ACTION_BAR); super.init();
动作条酒吧= getActionBar();
bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); //这里NPE被抛出
bar.addTab(bar.newTab()的setText(一些文本)setTabListener(新CustomTabListener()));


解决方案

所以,我最终没有能够解决这个而不修改原始code。最后我做什么是复制DroidGap类为我自己的类(来源$ C ​​$ C在帖子链接),并注释掉以下行:

  getWindow()requestFeature(Window.FEATURE_NO_TITLE)。

然后,我伸出我的正常活动与我的DroidGap,没有的PhoneGap的版本的修改版本。

于是,在我的活动的onCreate,我有这样的事情:

 公共无效的onCreate(捆绑savedInstanceState){
    super.onCreate(savedInstanceState);    。getWindow()requestFeature(Window.FEATURE_ACTION_BAR);    动作条酒吧= getActionBar();
    bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    bar.addTab(bar.newTab()的setText(家)setTabListener(新CustomTabListener()));
    bar.addTab(bar.newTab()的setText(东西)setTabListener(新CustomTabListener()));    使用loadURL(文件:///android_asset/www/index.html);
}

如果没有requestFeature,你会从 getActionBar()获得

希望它可以帮助别人!

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()));

解决方案

So, I ended up not being able to solve this without modifying the original code. What I ended up doing was copying the DroidGap class into my own class (source code linked in the post) and commented out the following line:

getWindow().requestFeature(Window.FEATURE_NO_TITLE);

Then, I extended my normal activity with my modified version of DroidGap, not PhoneGap's version.

Then, in my activity's onCreate, I have something like this:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    getWindow().requestFeature(Window.FEATURE_ACTION_BAR);

    ActionBar bar = getActionBar();
    bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    bar.addTab(bar.newTab().setText("Home").setTabListener(new CustomTabListener()));
    bar.addTab(bar.newTab().setText("Something").setTabListener(new CustomTabListener()));

    loadUrl("file:///android_asset/www/index.html");
}

Without the requestFeature, you'll get null from the getActionBar().

Hope it helps someone else!

这篇关于使用PhoneGap的时候添加标题回的Andr​​oid窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆