Reputation: 1875
what I want to achieve is activity with dialog-like transparency with 100% visibility of RelativeLayout content. This is activity's xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="50dip"
android:layout_marginLeft="8dip"
android:layout_marginRight="8dip"
android:layout_marginTop="50dip">
(...)
</RelativeLayout>
</LinearLayout>
and this is manifest:
<activity
android:name="com.acentic.rcontrol.activities.MyActivity"
android:theme="@android:style/Theme.Translucent.NoTitleBar" >
</activity>
Right now background is still visible, what am I doing wrong?
--- EDIT: I added
android:background="#c0000000"
to LinearLayout. Now background is transparent as I wanted to, but also TextViews inside RelativeLayout are also transparent.. how to change it?
Upvotes: 14
Views: 46567
Reputation: 615
If your activity needs to extends from AppCompatActivity, you can create a custom style for your activity
<style name="transparentActivity" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:colorBackgroundCacheHint">@null</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowAnimationStyle">@android:style/Animation</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
</style>
And then change the default style of your activity in the Manifest
<activity android:name=".MyActivity"
android:theme="@style/transparentActivity"/>
Otherwise, if you do not need your activity to extend from AppCompatActivity, just change the theme of your activity in the manifest in this way.
<activity android:name=".MyActivity"
android:theme="@android:style/Theme.Translucent.NoTitleBar"/>
Upvotes: 1
Reputation: 16043
I added android:background="#c0000000" to LinearLayout. Now background is transparent as I wanted to, but also TextViews inside RelativeLayout are also transparent.. how to change it?
Add a solid background to your RelativeLayout
element.
This way the RelativeLayout
will have a solid background, and only the margins will be transparent.
Upvotes: 3
Reputation: 5721
Create Style
<style name="MyTransparentTheme" parent="android:Theme.Dialog">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</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>
this is manifest:
<activity
android:name="your package.activity"
android:theme="@style/MyTransparentTheme">
</activity>
Upvotes: 7
Reputation: 4081
After setting LinearLayout transparency try to set it's child transparency to the value that you want. This should make them have different transparency than LinearLayout. Try it.
Upvotes: 0
Reputation: 2362
Try to set
getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
in your activity.
You can also try to do this in a style:
<style name="AppTheme" parent="@android:style/Theme.Translucent.NoTitleBar">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:colorBackgroundCacheHint">@null</item>
</style>
Upvotes: 12