I have tried lots of to make activity or main layout transparent using theme defined into style.xml
with different different attribute in theme still not working.
Only view.setalpha(0)
that makes layout or activity is transparent, but how to possible through style.xml
. I am using Theme.AppCompact
for support lower version of Android device.
Also i have tried lots of SO answer but none of one is working. What i am doing wrong or any correction there? what I have done so far is as following.
Please help me to solve the issue.
style.xml
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="Theme.AppCompat.Translucent" parent="AppTheme">
<item name="android:background">@android:color/transparent</item> <!-- Or any transparency or color you need -->
<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:windowContentOverlay">@null</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:windowAnimationStyle">@android:style/Animation</item>
</style>
</resources>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="demo.intel.com.serviceprogressbarnotification">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:theme="@style/Theme.AppCompat.Translucent">
</activity>
<activity android:name=".TestActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Well I have same case but I wanted to make my window to act like dialog and on the background of it I put my required transparency level. here is the style I used:
<style name="transparent_alertDialog" parent="Theme.AppCompat.Dialog.Alert"> <item name="windowNoTitle">true</item> <item name="android:windowActionBar">false</item> <item name="android:windowBackground">@android:color/transparent</item> <item name="android:backgroundDimAmount">0.95</item> <item name="android:windowFullscreen">false</item> <item name="android:windowIsFloating">true</item> <item name="android:windowMinWidthMajor">50%</item> <item name="android:windowMinWidthMinor">50%</item> <item name="android:windowContentOverlay">@null</item> <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item> <item name="android:windowCloseOnTouchOutside">false</item> </style>
and in manifest I used it like :
<activity
android:name=".PaymentConfirmationActivity"
android:label=""
android:theme="@style/transparent_alertDialog"
android:windowSoftInputMode="adjustPan"/>
So it did the trick for me. Hope so it will help for you too.