我基于我的第一个TWA / PWA应用repository构建。一切正常,但是我无法更改状态栏的颜色。
我修改了此file并将此行添加到<style>
标签中:
<item name="android:statusBarColor">@color/ic_launcher_background</item>
问题是...它可以很好地在App的第一个init上运行...但是在第一次init后500毫秒,它将启动Web视图,并且statusBarColor再次变为白色。
有什么主意我可以解决这个问题吗?
答案 0 :(得分:2)
已更新: 支持库(e849e45c90)的最新版本已更新,可以更轻松地更改状态栏颜色。
SVGOMG sample已更新为可以使用,并且可以在此pull request中看到应用程序进行必要的更改。
以下部分已过时,但此处保留历史背景
打开“自定义标签意图”时可以通过自定义状态栏颜色来进行更改。
目前在清单中无法配置此文件,主要方法是:
protected CustomTabsIntent getCustomTabsIntent(CustomTabsSession session) {
return new CustomTabsIntent.Builder(session)
.setToolbarColor(Color.parseColor("#FF0000"))
.build();
}
上面的代码将创建一个红色状态栏。将#FF0000
替换为所需的颜色。
答案 1 :(得分:0)
尝试在onResume()上添加此代码
public void setStatusBarColor(int color) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().setStatusBarColor(color);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
}
答案 2 :(得分:0)
您应该在您已声明“受信任的网络活动” (android.support.customtabs.trusted.STATUS_BAR_COLOR)的AndroidManifest上添加新的元数据
<activity android:name="android.support.customtabs.trusted.LauncherActivity">
<meta-data
android:name="android.support.customtabs.trusted.DEFAULT_URL"
android:value="https://your-host.com/" />
<meta-data
android:name="android.support.customtabs.trusted.STATUS_BAR_COLOR"
android:resource="@color/colorPrimaryDark" />
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE"/>
<data
android:scheme="https"
android:host="your-host.com"/>
</intent-filter>
</activity>