【发布时间】:2014-12-22 11:10:02
【问题描述】:
我和朋友一起创建了一个 Android 应用程序,但我遇到了一个与 UI 相关的奇怪问题。
在片段之间切换时,有时 UI 会出现混乱,请在下方创建一个故障。
它发生在我的 Nexus 5 上,带有 Dalvik 运行时和普通的 Android,我朋友的 Nexus 4 上带有 ART 运行时和 SlimKat rom。但在另一个带有 Dalvik 运行时和 4.4.2 (AOSB rom) 的 Nexus 5 上无法观察到。奇怪的是,在我更新到最新版本的应用程序之前,它并没有发生。
下面是使用的布局,其中main_fragment是我使用事务放置Fragment的地方。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<FrameLayout
android:id="@+id/main_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
</RelativeLayout>
我发现执行此行时会出现故障,而我在setBackgroundDrawable方法中放了什么并不重要:
activity.getActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor(getCurrentTheme(activity))));
还有其他人有这个问题吗?或者也许有人知道一种解决方法或如何使其工作?
编辑:我需要在运行时更改 ActionBar 颜色(在应用设置中更改主题)。
【问题讨论】:
-
通过样式/主题设置actionbarcolor,这会使执行的行变得多余
-
在此处查看有关样式操作栏背景的官方文档:developer.android.com/training/basics/actionbar/…
-
@user1281750 它不起作用,因为我需要在运行时更改 ActionBar 颜色。
标签: android user-interface android-fragments android-actionbar visual-glitch