gpt4 book ai didi

android - Activity 应该是透明的,但有黑色背景

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:03:54 47 4
gpt4 key购买 nike

我的用例是为风景相机预览编写覆盖 Controller Activity 。我按照几个教程中的说明编写透明主题。

所以我的 res/values/style.xml 看起来像这样:

<resources>

<style name="Theme" parent="android:Theme" />

<style name="Theme.Transparent">
<item name="android:windowBackground">@drawable/transparent_background</item>
</style>

<drawable name="transparent_background">#00000000</drawable>

</resources>

Activity fragment :

    <activity android:name=".CameraPreview"
android:label="Camera"
android:screenOrientation="landscape"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity android:name=".Controlls"
android:label="Controlls"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Translucent">
</activity>

当我从我的根 Activity 开始这个 Activity 时,布局被正确绘制,但背景保持黑色。我尝试使用 @android:style/Theme.Translucent 代替,但是这个主题继承了调用 Activity (横向)的方向,这不是我想要的。

编辑:

保存相机预览的应用程序设置为横向 View ,因为它不能正确显示纵向预览。 (参见 old google bug report)

我想做的是在camera surface holder前面放一个独立的用户交互界面activity(这个activity应该设置为'portrait',或者最好设置为'sensor')

最佳答案

对于有类似问题的其他人,这里有一些相关的答案。

tl;dr
添加名称是现有样式后缀的新样式可能会导致问题(例如使透明 Activity 具有黑屏)。


问题:经过大规模重构后,我们的透明 Activity 背景变为黑色。 (Activity 已经使用了透明主题。)

经过几个小时的提交后,我发现似乎是问题的原因。在我们的应用程序中,我们使用 CSS 等样式。我们将现有样式应用于 TextView。

<style name="HeadLine.SM.White.MyFontBold">
<item name="android:fontFamily">@font/some_bold_font</item>
</style>

样式的非粗体变体被添加为粗体变体之前的样式,如下所示。

//This style was added
<style name="HeadLine.SM.White.MyFont">
<item name="android:fontFamily">@font/some_font</item>
</style>

<style name="HeadLine.SM.White.MyFontBold">
<item name="android:fontFamily">@font/some_bold_font</item>
</style>

出于某种原因,在添加非粗体样式变体后,所有透明 Activity 都有黑屏。当我们将非粗体变体样式名称更改为其他名称时,它为我们解决了问题。现在我们的样式看起来像这样(我知道有更好的方法来处理字体样式 - 这些样式已经有几年了)

<style name="HeadLine.SM.White.MyFontRegular">
<item name="android:fontFamily">@font/some_font</item>
</style>

<style name="HeadLine.SM.White.MyFontBold">
<item name="android:fontFamily">@font/some_bold_font</item>
</style>

结论

添加名称是现有样式后缀的新样式似乎会导致问题。如果您要添加新样式,请确保该名称不是现有样式的后缀。

我们确实尝试清理构建、重建和使 Android Studio 缓存失效。这些都没有解决我们的问题。

关于android - Activity 应该是透明的,但有黑色背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2687712/

47 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com