0

When we change brightness, its activity become transparent So We can see the home screen/ another app that running behind. I want (100% same like Brightness seekbar) on my custom seekbar.

My App main activity background color is gray,

I want when seekbar drag: My activity becomes transparent and show background activities/Background Home screen,

When drag completes its back to normal on gray background.

My Research:

I search on transparent activities, I found many questions and many different styles and theme options.

Here is my last try:

<activity android:name=".Activity" 
     android:theme="@android:style/Theme.Translucent">

Every time when I follow StackOverflow answers, I get this error:

"You need to use a Theme.AppCompat theme (or descendant) with this activity."

=>I also try, Transparent background color, Transparent drawable, transparent from manifest,

Result: Background show white, not transparent

I have just 1 main activity, with custom brightness seekbar and other options.

My Manifest file

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="st.package">

<uses-permission 
android:name="android.permission.ACTION_MANAGE_OVERLAY_PERMISSION"/>
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity"
        android:theme="@android:style/Theme.Translucent">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>


    <service android:name="st.package.ChatHeadService"
        android:exported="true">
    </service>

    <receiver android:name="MainActivity$switchButtonListener" />
</application>

MainActivity.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="overlayhead.overlayhead.MainActivity"
android:orientation="vertical"
android:windowIsTranslucent="true"
android:id="@+id/LinearLayout"
android:background="@android:color/transparent"
>
Paolo Forgia
  • 6,572
  • 8
  • 46
  • 58
Asad Raza
  • 34
  • 1
  • 2
  • 14
  • see this link and take idea what ever u want. 1)[remove background of seekbar](https://stackoverflow.com/questions/2459326/android-remove-seekbar-background) 2)[transparent seek bar](https://stackoverflow.com/questions/26989400/custom-seekbar-thumb-not-transparent-on-lollipop-api21) – Kevan Aghera Jun 14 '17 at 11:52
  • see this link and take idea what ever u want. 1)[remove background of seekbar](https://stackoverflow.com/questions/2459326/android-remove-seekbar-background) 2)[transparent seek bar](https://stackoverflow.com/questions/26989400/custom-seekbar-thumb-not-transparent-on-lollipop-api21) – Kevan Aghera Jun 14 '17 at 11:54

2 Answers2

2

"You need to use a Theme.AppCompat theme (or descendant) with this activity."

It is because you need to use an AppCompat Theme. So you can define a custom theme in your styles.xml and use it as the theme for your desired Activity.

<style name="Theme.AppCompat.Translucent" 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>
    </style>

in your manifest file, declare Theme.AppCompat.Translucent as your theme

<activity android:name=".MainActivity"
        android:theme="@style/Theme.AppCompat.Translucent">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
Darish
  • 11,032
  • 5
  • 50
  • 70
  • I just add your style in my style.xml, in manifest activity android:theme="@android:style/Theme.Translucent" ---- still return same error... Please check question, i add my complete manifest file – Asad Raza Jun 14 '17 at 11:37
  • @AsadRaza in your manifest, you need to use Theme.AppCompat.Translucent. see my edit – Darish Jun 14 '17 at 11:39
  • Like this? android:theme="@android:style/Theme.AppCompat.Translucent" ---- Its return error. "cannot resolved", your code in resource/values/style.xml – Asad Raza Jun 14 '17 at 11:42
  • nop, you don't need the android prefix since this is a custom theme, see my edited answer please – Darish Jun 14 '17 at 11:43
  • Love you.. thank you :) , Now tell me please, How can i change activity transparent and solid color at run time, from java code... – Asad Raza Jun 14 '17 at 11:51
  • now your activity is transperent, right? so you can change the baground of your parent FrameLayout in your Activity layout file at runtime to get your desired output. view.setBackground may be helpfull – Darish Jun 14 '17 at 11:54
1

for color transparency you should provide color code with 8 digits where first two digits just after # represent transparency in percentage so if you want white color with 50% transparency then you should write color value as "#50ffffff".

by using this technique in java you can do like this

yourLayout.setBackgroundColor(Color.parseColor("#"+i+"bdbdbd"));

where i will be from 00 to 99 as per value of i color transparency will be changed. so as per seekbar value increase and decrease value of i from 00 to 99.

  • I use your code in onCreate(), its change my activity background color lite and dark, not transparent. :( – Asad Raza Jun 14 '17 at 11:47
  • what is your actual layout background color and what color you are using to transparent? can you show me that sample? – Parth Munjpara Jun 14 '17 at 11:54
  • try by putting a temporary textview in relative layout and check again it will disappear when transparency is less. – Parth Munjpara Jun 14 '17 at 11:56
  • if it is really helpful then approve my answer. – Parth Munjpara Jun 14 '17 at 11:58
  • I remove all styles from activity to test your code... I test with "#"+20+"000000" ...... "#"+50+"000000" ..... "#"+80+"000000", Result is just gray and dark gray, not transparent – Asad Raza Jun 14 '17 at 11:59
  • try this "#"+00+"000000" by putting 00 transparency and 000000 is black color code so your layout behine that may be white so it look like gray. so it may be happening because I tried that try changing different color. you can see this in many tutorials also. – Parth Munjpara Jun 14 '17 at 12:04
  • Thank you, i use your code to improve @darish answer... +1 Vote,, now i can do transparent and solid color at run time... – Asad Raza Jun 14 '17 at 13:40