【问题标题】:Hide the action bar on Android on Titanium/ Alloy/ Appcelerator在 Titanium/Alloy/Appcelerator 上隐藏 Android 上的操作栏
【发布时间】:2017-03-16 19:54:36
【问题描述】:

如何在 Alloy/Titanium 上隐藏 Android 上的操作栏。我尝试了以下方法:

$.index.activity.actionBar.hide()

但它只是抛出错误:

 Cannot read property 'hide' of undefined

完整的错误信息如下:

[ERROR] :  TiExceptionHandler: (main) [1605,1605] ----- Titanium Javascript Runtime Error -----
[ERROR] :  TiExceptionHandler: (main) [0,1605] - In /alloy/controllers/index.js:359,27
[ERROR] :  TiExceptionHandler: (main) [1,1606] - Message: Uncaught TypeError: Cannot read property 'hide' of undefined
[ERROR] :  TiExceptionHandler: (main) [0,1606] - Source:     win.activity.actionBar.hide();
[ERROR] :  V8Exception: Exception occurred at /alloy/controllers/index.js:359: Uncaught TypeError: Cannot read property 'hide' of undefined

【问题讨论】:

  • 解决方案展示了隐藏操作栏的正确方法(使用主题或何时调用hide() 方法)
  • @miga 我似乎找不到关于何时调用隐藏函数的解决方案。它们仅通过为窗口提供主题来提供替代方法。
  • 见Via win.activity.actionBar.hide(); you can only hide the Action Bar when your window is finally opened. The main disadvantage is that sometimes you can see the Action Bar for a few milliseconds, because the window is initially created with Action Bar 所以你在open 事件中使用它。不过,在你的 tss 中使用 NoTitleBar 主题更容易。

标签: android titanium appcelerator appcelerator-titanium titanium-alloy


【解决方案1】:

有几件事情你需要看:

问题 1 - 是否要隐藏所有窗口的操作栏(意味着整个应用程序)?

问题 2 - 是否要在打开窗口并执行某些操作(即单击或滚动)后隐藏操作栏?

问题 3 - 你想隐藏几个窗口的操作栏并为其他窗口显示它吗?


答案 1:- 使用内置 Titanium 主题

方法一——在tiapp.xml文件中使用这个标签:

<android xmlns:android="http://schemas.android.com/apk/res/android">
    <manifest>
        <application android:theme="@style/Theme.AppCompat.NoTitleBar"/>
    </manifest>
</android>

方法 2 - 在 app.tss 中设置 theme 属性:

"Window[platform=android]":{
    theme : 'Theme.AppCompat.NoTitleBar'
}


答案 2:

这就是您遇到该问题的情况。只有在打开窗口时才能通过 .js 文件中的代码隐藏操作栏。您必须使用 window 的 onOpen 事件 来运行此代码:

$.index.activity.actionBar.hide();

所以,一定是这样的:

$.index.addEventListener('open', function () {
   $.index.activity.actionBar.hide();
});

或者您可以在单击某个按钮时运行 hide() 方法,因为当显然该窗口打开时您将能够单击按钮,如下所示:

$.someButton.addEventListener('click', function () {
   $.index.activity.actionBar.hide();
});


答案 3:

通过Answer 1的方法2,您可以在.tss或.xml文件中应用主题来隐藏各个窗口的动作栏并且不要在有操作栏的窗口上应用任何主题。


在此处阅读更多信息 Titanium Android Themes

【讨论】:

  • 很好地解释了不同的方法。您可能想要编辑 A1) 方法 1 以列出正确的主题并说它在 tiapp.xml
  • 谢谢@miga :) .. .. 抱歉,这是拼写错误。 :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-03-18
  • 2012-02-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多