- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我有一个 fragment ( fragment 1)被另一个 fragment ( fragment 2)替换。 fragment 1 放在堆栈上。我正在使用兼容模式(不是 ActionBarSherlock)。
这是我的问题。我希望操作栏在某些 fragment 中显示为叠加层,但在其他 fragment 中不显示。具体来说,当显示 Fragment 2 时,我希望它出现在叠加层中,然后在 Fragment 2 退出后返回到正常的操作栏。
fragment 1 有一个始终可见的常规操作栏。但是,当我用 fragment 2 替换 fragment 1 时,我需要在 5 秒后隐藏操作栏。如果有触摸事件,将再次显示操作栏。这一切都很好,但是,每次隐藏或显示操作栏时,都会重新绘制 Fragment 2。因此,我想让 Fragment 2 中的操作栏显示为叠加层。
我知道我可以更改操作栏叠加层,但我不知道如何从 fragment 中以编程方式执行此操作。我不想为每个 fragment 更改它,只是 fragment 2。
想法??????
最佳答案
这可能不是您想要的答案。
考虑一个不同的问题:我们可以在调用 setContentView(...)
后更改 Activity 主题吗?这个问题已经被问了很多次,一个常见的解决方案是重新创建(调用 finish()
和 startActivity(getIntent())
) Activity 并在之前设置新主题setContentView(...)
。
您的问题是对此的扩展 - 增加了从 fragment 更改主题的复杂性。无论如何,我不认为上面提到的解决方案是好的。
ActionBar 是创建 Activity 时最先初始化的组件之一。我不认为你会找到一种方法来以某种方式用新属性“刷新”它。请参阅下面的 requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY)
方法如何处理 post-setContentView(...) 调用:
@Override
public boolean requestFeature(int featureId) {
if (mContentParent != null) {
throw new AndroidRuntimeException("requestFeature() must be
called before adding content");
}
....
....
}
因此,如果已经为 Activity 调用了 setContentView(...)
(在您的情况下是这样),将抛出运行时异常。
有没有可能你甚至不需要这个功能?
首先将 ActionBar 设置为主题中的叠加层:
<item name="android:windowActionBarOverlay">true</item>
<!-- Support library attribute for compatibility -->
<item name="windowActionBarOverlay">true</item>
Here's my problem. I want the actionbar to be displayed as overlay in some fragments...
好的。我们已经在上面对此进行了配置。
... but not in others.
假设您不想将 ActionBar 作为 Fragment B 中的叠加层。然后,在 Fragment B 的布局中,执行以下操作:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?android:attr/actionBarSize" > <<<-- ?attr/actionBarSize
for compatibility
....
....
</LinearLayout>
将上边距设置为 ActionBar 的大小后,Fragment B 看起来就像有一个常规的 ActionBar,而不是重叠的。实现此目的的另一种方法是将带有 android:layout_height="?android:attr/actionBarSize"
的 View
作为上面布局中的第一个子元素放置。
本质上:
actionBarSize
。注意事项(感谢 Jelle
):
如果您的 ActionBar
是半透明的,最好使用 padding 而不是 margin 以获得一致的外观。
关于android - 将操作栏更改为从 Fragment 中覆盖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24945244/
我使用 Runtime.getRuntime().exec 来运行 perl 程序。现在我想在执行过程中显示百分比进度条,然后在perl程序执行完成后,它应该关闭进度条。我该怎么做? Runtime.
我已广泛搜索该网站,但找不到答案。请我是新手,我需要你的帮助。 我想创建一个固定的导航栏,但每次在我的 CSS 样式表中放置一个固定的规则时,导航栏都会消失。这是我的 html 代码:
Here's a nice jsFiddle illustrating the problem 我正在尝试创建一个标题栏元素... 永远只有 1 行高 在右上角有始终存在的控件 在左上角有一个标题,如
int fd = open(JOYSTICK_NAME, O_RDONLY | O_NONBLOCK); O_RDONLY 和 O_NONBLOCK 之间的栏是什么意思?我在 OpenGL/GLUT
我注意到我的网页在页脚之后和页面底部有一个空白/栏: 我试图通过使用 Chrome 中的 inspect 元素来查找此问题的原因,但找不到任何内容。我正在使用 Boostrap,这是我的页脚 HTML
我已经对这个主题进行了一些研究,但我找不到完整的解决方案,因此,我一步一步地尝试和错误,我终于找到了如何实现这些结果:透明或彩色Actionbar 和 Statusbar。请参阅下面的答案。 最佳答案
Highcharts 教程中的经典示例是: $(function () { $('#container').highcharts({ chart: { type: 'bar'
注意 :这与 iOS 13 中使用的新默认模态呈现样式无关。 我有一个奇怪的问题,显示模态 UINavigationController . 考虑一个 UIViewController位于 UINav
我需要帮助了解如何在加载页面时隐藏 iPad 地址栏或顶部的整个地址栏。 我正在开发基于在线客户管理系统的系统,需要隐藏 iPad 地址栏,因为它在查看网站时会占用大量空间。 问候涡流 已经尝试了以下
我在向栏中添加文本时遇到了一些问题。我想在栏上方显示值,但我无法向每个栏添加文本。 现在我的dom结构是: g rect rect rect 我想要什么: g g.bar rect
我有 ListView ,数据将从数据表显示在 ListView 中像这样我已经完成了但是我在数据行 6 有问题 dt = classes.xxxxx.GetData(sql,
我使用 opposite 属性将 xAxis 向右移动。条形图怎么可能也从右侧开始? 谢谢! Highcharts.chart('absoluteInterruptions', { chart:
我得到了这张图片,我想在我的导航 Controller 中使用它: 我是这样设置的(根据 this 问题的建议): UINavigationBar *theBar = self.navigationC
这个问题在这里已经有了答案: How to disable breadcrumbs in Eclipse (11 个答案) 关闭 9 年前。 有谁知道如何删除我在 Eclipse 中用红色圈出的栏?
总而言之,我的应用程序中有一个浏览器,我希望它只启动 5 个网站,仅此而已。有没有办法让我的浏览器通过设置自定义字符串来启动 5 个网站,例如 if {用户键入此字符串} 转到该网站,然后 else
我想在我的应用程序中实现一个进度条。发生的过程是应用程序将一个目录复制到 iOS 文档目录中。通常需要 7-10 秒(iPhone 4 测试)。我对进度条的理解是你在事情发生时更新进度条。但是根据目录
我正在寻找一种创建交互式子弹图的方法,它允许用户单击图中的任意位置并设置一个标记,然后根据该标记所在的位置计算一些简单的值。例如,我希望它看起来类似于: http://www.usrecordings
我目前在一个网站上工作,我有一张人的照片。在图片的右侧,我想要名称和描述。名称应与描述具有不同的背景。我上传了一张它应该是什么样子的图片:http://www.tiikoni.com/tis/view
我将 div 栏设置为不滚动,因此它将始终显示在网站顶部。在这个栏内,我有另一个 div 框,里面有两个按钮,它们向右浮动,所以它们总是在右上角。 问题是我希望按钮居中于页面的右上角而不是右上角。相反
因此,我在我的网站中使用了一个选择栏。我试图在悬停时更改选项的背景颜色。此外,如果有人知道设置垂直 slider 样式的好方法,那就太棒了。 这是我正在尝试做的事情的 fiddle : http://
我是一名优秀的程序员,十分优秀!