我正在尝试在另一个 Activity 上设置一个透明的 Activity ,该 Activity 具有淡淡的灰色色调。我能够调用透明 Activity ,但无法获得灰色调。请帮我。以下是我的代码。
<style name="Theme.Transparent">
<item name="android:windowBackground">@drawable/transparent_background</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
<drawable name="transparent_background">#FFFECA11</drawable>
无论我为可绘制对象提供什么颜色值,它都不会反射(reflect)为背景。 list 中的定义
<activity
android:name=".DisplayHelpActivity"
android:label="@string/title_activity_display_help"
android:theme="@style/Theme.Transparent">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.INFO" />
</intent-filter>
</activity>
你能告诉我 wat 不见了吗? 附言请忘记颜色值。它只是随机的,我用来测试它是否有效。
我也用了下面的
<item name="android:windowBackground">@color/transparent</item>
而不是 drawable,在我的 color.xml 中
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="transparent">#80ffeeca</color>
</resources>
还是没有效果。请帮助我。
最佳答案
我不认为将 Activity 放在彼此之上是个好主意。如果你想在你的正常 Activity 之上显示一些东西,那么使用 FrameLayout
是一个可能的解决方案:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/main_layout" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffffff"
android:id="@+id/underlying_layout" >
<!--Put the parts of your normal activity here -->
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#88666666"
android:id="@+id/top_layout">
<!--Put the parts of the layout here,
what should be on top of your activity-->
</LinearLayout>
</FrameLayout>
现在如果你想让顶层的东西出现或消失,那么你可以使用 View setVisibility()
像这样的功能:
View topLevelLayout = findViewById(R.id.top_layout);
//make it disappear with all its sub-Views
topLevelLayout.setVisibility(View.INVISIBLE);
//make it appear with all its sub-Views
topLevelLayout.setVisibility(View.VISIBLE);
更新
关于android - 透明 active ,带有淡淡的灰色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12230686/